0

Code not working

Hey , my code is : String m = args[0]; int n = Integer.parseInt(m); String[] array = new String[n]; boolean z = false; for (int i = 0 ; i < n ; i++){ array[i] = JOptionPane.showInputDialog("Geben sie einen Namen ein"); } String vergleich = JOptionPane.showInputDialog("Geben sie einen weiteren Namen ein."); for (int i = 0 ; i < n ; i++){ if (vergleich.equals(array[i])){ System.out.println(i); z = true; break; } } if (z == false); System.out.println("Name nicht vorhanden"); But the z does not get set to true whether the equals statement is true or not. When it is true everything else works right , the System.out.println(i) and break is both working right. But the z = true; does not work because the last if statement is triggered in every case , when the equals statement is true or not. Would be nice if someone could help me!

5th Jan 2021, 5:41 PM
Kevin S
Kevin S - avatar
2 ответов
+ 1
this is not the problem. the issue is that you added a semicolon ';' after the last if statement. if(z==false); //<-- remove the semicolon
5th Jan 2021, 6:35 PM
John Robotane
John Robotane - avatar
0
Wow I saw it...thank you!
5th Jan 2021, 6:36 PM
Kevin S
Kevin S - avatar