Advertisement
Shad0w

Untitled

Sep 20th, 2011
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. //Java Calculator
  2. import java.util.Scanner;
  3. class sample
  4. {
  5.     public static void main(String[]args)
  6.     {
  7.         //Setting vars
  8.         int answer=1;
  9.         int num1,num2,num3;
  10.         Scanner input=new Scanner(System.in);
  11.         while (answer==1)
  12.         {
  13.             System.out.print("Choose number : \r\n 1 - Plus \r\n 2 - Minus \r\n 3 - Multiplication \r\n 4 - Divide : ");
  14.             num3 = input.nextInt();
  15.             if (num3==1)
  16.             {
  17.                 System.out.print("Choose number:");
  18.                 num1 = input.nextInt();
  19.                 System.out.print("Choose other number: ");
  20.                 num2 = input.nextInt();
  21.                 System.out.print("\r\n" + num1 + " + " + num2 + " = ");
  22.                 System.out.print(num1+num2);
  23.                 System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
  24.                 answer = input.nextInt();
  25.             }
  26.             if (num3==2)
  27.             {
  28.                 System.out.print("Choose number:");
  29.                 num1 = input.nextInt();
  30.                 System.out.print("Choose other number: ");
  31.                 num2 = input.nextInt();
  32.                 System.out.print("\r\n" + num1 + " - " + num2 + " = ");
  33.                 System.out.print(num1-num2);
  34.                 System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
  35.                 answer = input.nextInt();
  36.             }
  37.             if (num3==3)
  38.             {
  39.                 System.out.print("Choose number:");
  40.                 num1 = input.nextInt();
  41.                 System.out.print("Choose other number: ");
  42.                 num2 = input.nextInt();
  43.                 System.out.print("\r\n" + num1 + " x " + num2 + " = ");
  44.                 System.out.print(num1*num2);
  45.                 System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
  46.                 answer = input.nextInt();
  47.             }
  48.             if (num3==4)
  49.             {
  50.                 System.out.print("Choose number:");
  51.                 num1 = input.nextInt();
  52.                 System.out.print("Choose other number: ");
  53.                 num2 = input.nextInt();
  54.                 System.out.print("\r\n" + num1 + " / " + num2 + " = ");
  55.                 System.out.print(num1/num2);
  56.                 System.out.print("\r\n Do you wish to continue ? (1 For Yes 0 For No) : ");
  57.                 answer = input.nextInt();
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement