package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner kbReader = new Scanner(System.in);
System.out.print("Choose mode (\"words\" or \"symbols\"): ");
String mode = kbReader.nextLine();
if ("words".equals(mode))
{
String oa = " plus ";
String os = " minus ";
String om = " times ";
String od = " divided by ";
String e = " equals ";
}
else
{
String oa = " + ";
String os = " - ";
String om = " * ";
String od = " / ";
String e = " = ";
}
System.out.println("Choose your operation:");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.print("Your choice: ");
Scanner kbReader2 = new Scanner(System.in);
int choice = kbReader2.nextInt();
if (choice > 4)
{
System.out.println("You must enter a 1, 2, 3, or 4.");
return;
}
System.out.print("Enter first integer: ");
int op1 = kbReader.nextInt();
System.out.print("Enter second integer: ");
int op2 = kbReader.nextInt();
System.out.println("");
switch (choice)
{
case 1:
System.out.println(op1 + oa + op2 + e + (op1 + op2));
break;
case 2:
System.out.println(op1 + os + op2 + e + (op1 - op2));
break;
case 3:
System.out.println(op1 + om + op2 + e + (op1 * op2));
break;
case 4:
System.out.println(op1 + od + op2 + e + ((double)op1 / op2));
break;
}
}
}
This won't run correctly for some reason. It tells me that the variables oa, os, om, od, and e can not be found, but I declared and initialized them earlier in my first if-then statements...