A simple Calculator.
import java.util.Scanner;
public class Calc {
public static void main(String[] args)throws Exception{
int op = 0;
Scanner scan = new Scanner(System.in);
double num1, num2, ans;
do{
do{
System.out.println("1 for addition. 2 for subtraction. 3 for multiplication. 4 for division");
op = scan.nextInt();
}while(op<1 && op>4);
if(op==1)
{
System.out.println("Input your first number: ");
num1 = scan.nextDouble();
System.out.println("Input your second number: ");
num2 = scan.nextDouble();
ans = num1+num2;
System.out.println(ans);
}
if(op==2)
{
System.out.println("Input your first number: ");
num1 = scan.nextDouble();
System.out.println("Input your second number: ");
num2 = scan.nextDouble();
ans = num1-num2;
System.out.println(ans);
}
if(op==3)
{
System.out.println("Input your first number: ");
num1 = scan.nextDouble();
System.out.println("Input your second number: ");
num2 = scan.nextDouble();
ans = num1*num2;
System.out.println(ans);
}
if(op==4)
{
System.out.println("Input your first number: ");
num1 = scan.nextDouble();
System.out.println("Input your second number: ");
num2 = scan.nextDouble();
ans = num1/num2;
System.out.println(ans);
}
System.out.println("Again? y/n");
}while(scan.next().equals("y"));
}
}