Logo 
Search:

C++ Programming Answers

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds
  Question Asked By: Fiqah Roslan   on May 23 In C++ Programming Category.

  
Question Answered By: Abhishek Singh   on May 23

package calc;

02

03 import java.util.Scanner; //Get User inpurt

04 import java.text.NumberFormat; //

05

06

07

08 public class Main {

09 public static void main(String[] args){

10

11 Scanner input = new Scanner(System.in);

12

13

14 System.out.println("Welcome to Calc 1.0!");

15 System.out.println("This is the main menu");

16 System.out.println("Choose your exp<B></B>ression: ");

17 System.out.println("1. Addition /n 2. Substraction/n 3. Multiplcation /n 4. Divide ");

18

19 int choice = input.nextInt();

20

21 switch (choice){

22

23 case 1:

24 addition();

25 case 2:

26 substraction();

27 case 3:

28 multiplication();

29 case 4:

30 divide();

31 }

32 }

33

34 static void addition(){

35 Scanner math1 = new Scanner(System.in);

36 double a;

37 double b;

38 double c;

39 System.out.println("First Num");

40 a = math1.nextInt();

41 System.out.print("Second Num");

42 b = math1.nextInt();

43 c = a + b;

44 System.out.println ("The total value is " + c);

45 return;

46 }

47 static void substraction() {

48 Scanner math1 = new Scanner(System.in);

49 double a;

50 double b;

51 double c;

52 System.out.println("First Num");

53 a = math1.nextInt();

54 System.out.print("Second Num");

55 b = math1.nextInt();

56 c = a - b;

57 System.out.println ("The total value is " + c);

58 return;

59 }

60 static void multiplication(){

61 Scanner math1 = new Scanner(System.in);

62 double a;

63 double b;

64 double c;

65 System.out.println("First Num");

66 a = math1.nextInt();

67 System.out.print("Second Num");

68 b = math1.nextInt();

69 c = a * b;

70 System.out.println ("The total value is " + c);

71 return;

72 }

73 static void divide(){

74

75 Scanner math1 = new Scanner(System.in);

76 double a;

77 double b;

78 double c;

79 System.out.println("First Num");

80 a = math1.nextInt();

81 System.out.print("Second Num");

82 b = math1.nextInt();

83 c = a / b;

84 System.out.println ("The total value is " + c);

85 return;

86 }

87 }

Share: