I have made a calculator programme and with scanner I am taking the user input and storing that input in a variable and comparing that using if else statement. If the user says " Yes" then I will run specific method accrodingly else I will exit the programme. But I am not able to comare the user value here in If statement. Please have a quick look on my programme made:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Do you want to use my calculator? Y/N");
String value = sc.next();
if(value == "Y") {
System.out.println("Which method you want to use? 1.Add 2.Subtract 3.Multiplication 4. Division 5.Modulus");
String b = sc.next();
System.out.println("Please enter 1st number");
int x = sc.nextInt();
System.out.println("Please enter 2nd number");
int y = sc.nextInt();
add(x, y);
subtraction(x, y);
multiplication( x, y);
division(x, y);
modulus (x,y);
}
else
{
String c = "You can exit the programme";
}
}
Aucun commentaire:
Enregistrer un commentaire