So i am very new to java. I've been messing around with some if statements using the scanner to test user input. When i run the program, three out of the four if statements work. The fourth runs as the third... I don't know why this is. Here is my code. Hopefully you guys have some suggestions.
import java.io.*;
import java.util.Scanner;
public class TestFile5
{
public static void main(String[] args) throws IOException
{
//Have two choices? Simple and complicated? Simple example = input (X) input. Complicated = below
Scanner user_input = new Scanner(System.in);
System.out.println("Choose calculation type: Long or Short");
String choicetype;
System.out.print("Type: ");
choicetype = user_input.next();
String selection;
if(choicetype.equals("Long"))
{
System.out.println("Selection: Long");
System.out.println(" ");
System.out.println("This is a calculator");
System.out.println("First select type of function");
System.out.println("1: Addition");
System.out.println("2: Subtraction");
System.out.println("3: Multiplication");
System.out.println("4: Division");
System.out.print("Selection: ");
selection = user_input.next();
if(selection.equals("Addition"))
{
System.out.println("Enter two numbers to add");
int first_number;
System.out.print("1: ");
first_number = user_input.nextInt();
int second_number;
System.out.print("2: ");
second_number = user_input.nextInt();
System.out.println(first_number + second_number);
System.exit(0);
}
if(selection.equals("Subtraction"))
{
System.out.println("Enter two numbers to subtract");
int first_number;
System.out.print("1: ");
first_number = user_input.nextInt();
int second_number;
System.out.print("2: ");
second_number = user_input.nextInt();
System.out.println(first_number - second_number);
System.exit(0);
}
if(selection.equals("Multiplication"));
{
System.out.println("Enter two numbers to multiply");
int first_number;
System.out.print("1: ");
first_number = user_input.nextInt();
int second_number;
System.out.print("2: ");
second_number = user_input.nextInt();
System.out.println(first_number * second_number);
System.exit(0);
}
//Does Not work. Trys to multiply
if(selection.equals("Division"))
{
System.out.println("Enter two numbers to divide");
int first_number;
System.out.print("1: ");
first_number = user_input.nextInt();
int second_number;
System.out.print("2: ");
second_number = user_input.nextInt();
System.out.print("Answer: ");
System.out.print(first_number / second_number);
System.exit(0);
}
}
if(choicetype.equals("Short"))
{
System.out.println("Selection: Short");
System.out.println("");
}
}
}