+ 1
Someone should help me check what's wrong with this code.
import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); if(myVar==7){ System.out.println("broke even"); } else if(myVar>7){ System.out.println("profit"); } else{ System.out.println("loss"); } } }
1 Réponse
+ 21
Olisa David for reading the integer values you need to make scanner object with nextInt() method.
import java.util.Scanner;
class MyClass {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int myVar=sc.nextInt();
if(myVar==7){
System.out.println("broke even");
}
else if(myVar>7){
System.out.println("profit");
}
else{
System.out.println("loss");
}
}
}