I started learning java recently
My problem is if I use static Scanner read= new Scanner(System.in);
and when I enter s1
value non-integer I'm getting this error:
Exception in thread "main" java.util.InputMismatchException at this line:
a = oku.nextInt(); in goster() method.
When I remove static Scanner read= new Scanner(System.in);
and activate commented line in goster() method everything works fine.
What changes when I use static that causes my code to fail?
public static void main(String[] args) {
while (check)
{
goster();
try
{
hatali=false;
System.out.print("1. sayi: ");
s1 = read.nextDouble();
System.out.print("2. sayi: ");
s2 = read.nextDouble();
} catch (Exception e)
{
System.out.println("HATALI SAYI GİRİŞİ!");
hatali=true;
}
if(hatali==false)
{
menu(a, s1, s2);
}
}
public static void goster() {
//Scanner read= new Scanner(System.in);
System.out.println("");
System.out.println("1- a+b");
System.out.println("2- a-b");
System.out.println("3- a*b");
System.out.println("4- a/b");
System.out.println("5- a%b");
System.out.println("6- a^b");
System.out.println("7- cikis");
System.out.print("seciminiz 1-7: ");
a = read.nextInt();
}