CALCULATOR

on 2:19 PM

import java.io.*;
import java.util.*;
public class calculator

{
public static void main(String[] args) throws IOException
{
BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));
String input, input1, input2;
int num1, num2, answer;

System.out.println ("\t\t\tWelcome to the calculator!");
do
{
System.out.print ("\nWould you like to Multiply(m), Divide(d), Subtract(s), Add(a)?: ");
input = keyboard.readLine();
if (input.equals("m"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1*num2;
System.out.print ("You chose to multiply."+"\t"+"The Product is: "+answer);
}
if (input.equals("d"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1/num2;
System.out.print ("You chose to divide."+"\t"+"The Dividend is: "+answer);
}
if (input.equals("a"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1+num2;
System.out.print ("You chose to add."+"\t"+"The Sum is: "+answer);
}
if (input.equals("s"))
{
System.out.print ("Please enter the first number!: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the second number!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
answer = num1-num2;
System.out.print ("You chose to subtract."+"\t"+"The Diffrence is: "+answer);
}

System.out.print ("\nWould you like another calculation (y/n)?: ");
input = keyboard.readLine();
}
while(input.equals("y"));
if(input.equals("n"));
System.exit(0);
}
}

1 comments:

rajesh said...

4m wher did u get dis program

Post a Comment