You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: General_purpose_calc.java
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,11 @@ public static void main(String[] args)
26
26
System.out.println(" - Press 2 if base and hypotenuse are given ");
27
27
System.out.println(" - press 3 if height and hypotenuse are given ");
28
28
doubleb, h, hp; // Declaring variables to be used in the following switch case
29
-
intchp;
30
-
chp = sc.nextInt();
29
+
charchp;
30
+
chp = sc.next().charAt(0);
31
31
switch(chp)
32
32
{
33
-
case1 :System.out.println(" > Enter the length of base ");
33
+
case'1' :System.out.println(" > Enter the length of base ");
34
34
b = sc.nextDouble();
35
35
System.out.println(" > Enter the length of height ");
36
36
h = sc.nextDouble();
@@ -39,7 +39,7 @@ public static void main(String[] args)
39
39
doublerhp = Math.sqrt(hp);
40
40
System.out.println(" Solved Hypotenuse is --> " + rhp );
41
41
break;
42
-
case2 :System.out.println(" > Enter the length of base ");
42
+
case'2' :System.out.println(" > Enter the length of base ");
43
43
b = sc.nextDouble();
44
44
System.out.println(" > Enter the length of hypotenuse ");
45
45
hp = sc.nextDouble();
@@ -49,7 +49,7 @@ public static void main(String[] args)
49
49
rh = Math.sqrt(h);
50
50
System.out.println(" Solved Height is --> " + rh );
51
51
break;
52
-
case3 :System.out.println(" > Enter the length of height ");
52
+
case'3' :System.out.println(" > Enter the length of height ");
53
53
h = sc.nextDouble();
54
54
System.out.println(" > Enter the length of hypotenuse ");
55
55
hp = sc.nextDouble();
@@ -64,14 +64,14 @@ public static void main(String[] args)
64
64
}
65
65
elseif(ch1 == '2') // This part gets executed if user enters "2"
66
66
{
67
-
intvnum;
67
+
charvnum;
68
68
System.out.println(" > Enter the number of terms ");
69
-
vnum = sc.nextInt();
69
+
vnum = sc.next().charAt(0);
70
70
switch(vnum)
71
71
{
72
-
case1 :System.out.println(" ERROR --> Number of terms can not be 1 <-- ");
72
+
case'1' :System.out.println(" ERROR --> Number of terms can not be 1 <-- ");
73
73
break;
74
-
case2 :doublet1, t2, a1; // Always use double type for making any kind of calculator as int does not allow use of decimals, and gives a type miss match error when a decimal term is entered
74
+
case'2' :doublet1, t2, a1; // Always use double type for making any kind of calculator as int does not allow use of decimals, and gives a type miss match error when a decimal term is entered
75
75
System.out.println(" > Enter the value of the first term ");
76
76
t1 = sc.nextDouble();
77
77
System.out.println(" > Enter the value of the second term ");
@@ -104,7 +104,7 @@ else if(tas == 4)
104
104
System.out.println(" Your answer is --> " + a1 );
105
105
}
106
106
break;
107
-
case3:doublet13, t23, t33;
107
+
case'3': doublet13, t23, t33;
108
108
System.out.println(" > Enter the value of the first term ");
109
109
t13 = sc.nextDouble();
110
110
System.out.println(" > Enter the value of the second term ");
0 commit comments