programming for Calculator in java

904 views

Published on

WAP to create equivalent of a four function calculator. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetic operation: addition, subtraction, multiplication and division of two numbers.(using nested if statement)

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
904
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

programming for Calculator in java

  1. 1. //Ques. 4 WAP to create equivalent of a four function calculator. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetic operation: addition, subtraction,multiplication and division of two numbers.(using nested if statement) importjava.util.Scanner; class calculator { public static void main(String arr[]) { inta,b,c,d,e,f,g; Scanner in = new Scanner(System.in); System.out.println("Which Operation You wanna Perform"); System.out.println("1. Addition"); System.out.println("2. Subtraction"); System.out.println("3. Multiplication"); System.out.println("4. Division n"); c = in.nextInt(); System.out.print("nEnter First Number = "); a = in.nextInt(); System.out.print("Enter Second Number = "); b = in.nextInt(); if(c==1) { d=a+b;
  2. 2. System.out.println("Addition is " +d); } else if(c==2) { e=a-b; System.out.println("Subtraction is " +e); } else if(c==3) { f=a*b; System.out.println("Multiplication is " +f); } if(c==4) { g=a/b; System.out.println("Division is " +g); } } }
  3. 3. OUTPUT:-

×