I am currently studying java at NetBeans.
Scanner sc=new Scanner (System.in);
System.out.print("Determination");
int x = sc.nextInt();
if(x>=0.4)
System.out.println("Determination A";
else if (x>=0.3&x<0.4)
System.out.println("Determination B";
else
System.out.println("Determination C";
when you type
If it's 1 or 0, it will run well.
If you type 0.5 or 0.2, you will get an error.
Please find out the cause.
The int type can be an integer, such as 1 or 0.
You must use double type (or float type) to represent decimal places such as 0.5 and 0.2.
For the code in question, doublex=sc.nextDouble();
instead of intx=sc.nextInt();
works.
Scanner sc=new Scanner (System.in);
System.out.print("Determination");
double x = sc.nextDouble();
if(x>=0.4)
System.out.println("Determination A";
else if (x>=0.3&x<0.4)
System.out.println("Determination B";
else
System.out.println("Determination C";
© 2024 OneMinuteCode. All rights reserved.