+ 1
Why this is not working
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan= new Scanner(System.in); System.out.println("CHOOSE AN OPERATOR * + / -"); String o= scan.nextLine(); System.out.println("Type Any Number"); int n1= scan.nextInt(); System.out.println("Type The Second Number:" ); int n2= scan.nextInt(); if (o=="+") { System.out.println(n1+n2); } }
3 Answers
+ 2
Use
(o.equals("+")) instead of (o=="+")
edit: you have a brace } missing at end. add it.
+ 2
Thank you i gotcha
0
In java, the operator == reference comparision while equal() method compares content of operands..
You're welcome..