1
I’m trying to fill a 5x5 matrix but when I run the ORDER in the finish entry, the code returns me the matrix filled with the word END.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Digite");
String s = sc.nextLine();
String m[][] = new String[5][5];
while (!s.equals("FIM")){
System.out.println("Digite:");
s = sc.nextLine();
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
m[i][j] = s;
}
}
}
sc.close();
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
System.out.println(m[i][j]);
}
}
}
}
Code out:
FIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIMFIM
desired output from the matrix with all letters typed:
q w e r t a d r t h j a v a s p y t h o t r e f g
the code must be able to be closed at any time at the FIM.
– Bruno