11-29-2009, 06:45 PM
Code:
import java.util.Scanner;
public class calc
{
public static void main(String[] args)
{
int x = 1;
while (x == 1)
{
Scanner num = new Scanner(System.in);
Scanner num2 = new Scanner(System.in);
Scanner op = new Scanner(System.in);
float userinput;
float userinput2;
int userinput3;
System.out.print("Enter a Number: ");
userinput = num.nextInt();
System.out.print("Enter Another Number: ");
userinput2 = num2.nextInt();
System.out.println("1) Add");
System.out.println("2) Subtract");
System.out.println("3) Multiply");
System.out.println("4) Divide");
System.out.print("Enter an Operation: ");
userinput3 = op.nextInt();
if (userinput3 == 1)
{
System.out.println(userinput + userinput2);
}
else if (userinput3 == 2)
{
System.out.println(userinput - userinput2);
}
else if (userinput3 == 3)
{
System.out.println(userinput * userinput2);
}
else if (userinput3 == 4)
{
System.out.println(userinput / userinput2);
}
else
{
System.out.println("Please enter a valid option...");
}
}
}
}