Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Java Calculator
- import java.util.Scanner;
- class sample
- {
- public static void main(String[]args)
- {
- //Setting vars
- int answer=1;
- int num1,num2,num3;
- Scanner input=new Scanner(System.in);
- while (answer==1)
- {
- System.out.print("Choose number : \r\n 1 - Plus \r\n 2 - Minus \r\n 3 - Multiplication \r\n 4 - Divide : ");
- num3 = input.nextInt();
- if (num3==1)
- {
- System.out.print("Choose number:");
- num1 = input.nextInt();
- System.out.print("Choose other number: ");
- num2 = input.nextInt();
- System.out.print("\r\n" + num1 + " + " + num2 + " = ");
- System.out.print(num1+num2);
- System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
- answer = input.nextInt();
- }
- if (num3==2)
- {
- System.out.print("Choose number:");
- num1 = input.nextInt();
- System.out.print("Choose other number: ");
- num2 = input.nextInt();
- System.out.print("\r\n" + num1 + " - " + num2 + " = ");
- System.out.print(num1-num2);
- System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
- answer = input.nextInt();
- }
- if (num3==3)
- {
- System.out.print("Choose number:");
- num1 = input.nextInt();
- System.out.print("Choose other number: ");
- num2 = input.nextInt();
- System.out.print("\r\n" + num1 + " x " + num2 + " = ");
- System.out.print(num1*num2);
- System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
- answer = input.nextInt();
- }
- if (num3==4)
- {
- System.out.print("Choose number:");
- num1 = input.nextInt();
- System.out.print("Choose other number: ");
- num2 = input.nextInt();
- System.out.print("\r\n" + num1 + " / " + num2 + " = ");
- System.out.print(num1/num2);
- System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
- answer = input.nextInt();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement