So I am doing this thing that asks you to enter how many numbers you want and then ask you to enter one more number. The code is supposed to check if that number was one of the numbers first submitted, if it was, a message will pop up saying it was and then exit the program. Can someone help me how to use the scanner correctly, or if that isn't the issue in my code, help me correct my code?
package individuellt_val;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class InlKap9test2 {
public static void main(String[] args) {
String s = JOptionPane.showInputDialog("Ange några tal");
Scanner sc = new Scanner(s);
int x = 0, y = 0;
boolean fortsätt = true;
while(fortsätt){
while(sc.hasNextInt()){
x = sc.nextInt();
String s2 = JOptionPane.showInputDialog("Ange ett tal till");
Scanner sc2 = new Scanner(s2);
while(sc2.hasNextInt())
y = sc.nextInt();
if(x == y){
JOptionPane.showMessageDialog(null, "Detta tal fanns bland de första!");
fortsätt = false;
}
}
}
System.exit(0);
}
}