Posts by Gabriel Pereira • 41 points
4 posts
-
1
votes3
answers2418
viewsA: How to make a rectangle of asterisks using for?
Scanner teclado = new Scanner(System.in); int n = teclado.nextInt(); int m = teclado.nextInt(); int temp = m; for( ; n > 0 ; n-- ){ for( temp = m; temp > 0 ; temp-- ){ System.out.print("*"); }…
-
1
votes3
answers103
viewsA: Why is this piece of code looping endlessly?
The mistakes are: String is reference, if you compare it to == it will return false unless you are talking about the same object. Ex: "1" == "1" returns false. " 1". equals("1") returns true You…
-
1
votes5
answers1088
viewsA: Digits in a java string
public static int contaDigitos(String arg) { int nums = 0; for(char ch : arg.toCharArray()){ if(Character.isDigit(ch)) nums++; } return nums; }
-
1
votes2
answers56
viewsA: Declare local classes as public
Simply declare a variable of type Enemy BEFORE THE switch and in the corresponding blocks you just initiating the variable, after all, it will already be declared.…
c++answered Gabriel Pereira 41