Hello, my name is Nick. I am fairly new to java and am trying to write some multiple choice programs but it seems to only run the whole program no matter what you choose. Here is my code, please help!
{
int ans;
Scanner input = new Scanner(System.in);
System.out.println("What would you like to do?");
System.out.println("1)Add 2)Subtract 3)Multiply");
ans = input.nextInt();
int x;
int y;
int sum;
if (ans == 1);
{
System.out.println("You have choosen addition!");
System.out.println("Please enter a number");
x = input.nextInt();
System.out.println("Please enter another number");
y = input.nextInt();
sum = x + y;
System.out.println("The sum of the two numbers is " + sum);
}
System.out.println();
if (ans == 2);
{
System.out.println("You have choosen subtraction!");
System.out.println("Please enter a number");
x = input.nextInt();
System.out.println("Please enter another number");
y = input.nextInt();
sum = x - y;
System.out.println("The subtraction of the two numbers is " + sum);
}
System.out.println();
if (ans == 3);
{
System.out.println("You have choosen multiplication!");
System.out.println("Please enter a number");
x = input.nextInt();
System.out.println("Please enter another number");
y = input.nextInt();
sum = x * y;
System.out.println("The multiplication of the two numbers is " + sum);
}
if (x <= 1 || x >= 3);
{
System.out.println("Invalid command, Try again!");
}
input.close();
}