Mahjabin Meem Mahjabin Meem - 22 days ago 5
Java Question

Can not print long variables

The following block of code prints nothing.
Input: 100 + 1
expected output: 101

Scanner Sc = new Scanner(System.in);
long n = Sc.nextLong();
String c = Sc.next();
long m = Sc.nextLong();
if(c == "+"){
long sum = m+n;
System.out.println(sum);
}
if(c == "*"){
long product = n*m;
System.out.println(product);
}

Joe Joe
Answer

For String comparison use .equals() not ==.