I am making a basic calculator. When I try to compare Strings and I use next()
, it works fine, however if I use nextLine()
, it doesn't work. How can this be? Aren't next
and nextLine
practically the same thing, just that one skips a line and one doesn't?
Here is my code:
import java.util.Scanner;
class apples{
public static void main(String args[]){
Scanner Max = new Scanner(System.in);
int num1, num2, answer;
String plumi;
System.out.println("enter your first number");
num1 = Max.nextInt();
System.out.println("enter your second number");
num2 = Max.nextInt();
System.out.println("enter if you want to use plus or minus");
plumi = Max.next();
if(plumi.equals("plus")){
answer = num1 + num2;
System.out.println("the answer is " + answer);
}
if(plumi.equals("minus")){
answer = num1 - num2;
System.out.println("the answer is " + answer);
}
}
}