-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_6.java
More file actions
105 lines (91 loc) · 2.63 KB
/
Copy pathlesson_6.java
File metadata and controls
105 lines (91 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*_______________________________*/
//! Switch statement!!
package Notes;
import java.util.Scanner;
public class lesson_6 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter Your Grade: ");
char grade = input.next().charAt(0);
switch (Character.toUpperCase(grade)){
case 'A':
System.out.println("Excellent");
break;
case 'B':
System.out.println("Very Good");
break;
case 'C':
System.out.println("Good");
break;
case 'D':
System.out.println("Fair");
break;
case 'F':
System.out.println("Failed");
break;
default:
System.out.println("Invalid Grade!!!");
}
int choice;
System.out.println("The Choices are:");
System.out.println("1. Add two numbers");
System.out.println("2. Sub two numbers");
System.out.println("3. Get the square of a number");
System.out.print("Enter Your Choice: ");
choice = input.nextInt();
int num1,num2;
switch (choice){
case 1:
System.out.print("Enter the first number: ");
num1 = input.nextInt();
System.out.print("Enter the second number: ");
num2 = input.nextInt();
System.out.printf("The equation is %d + %d = %d %n",num1,num2,num1+num2);
break;
case 2:
System.out.print("Enter the first number: ");
num1 = input.nextInt();
System.out.print("Enter the second number: ");
num2 = input.nextInt();
System.out.printf("The equation is %d - %d = %d %n",num1,num2,num1-num2);
break;
case 3:
System.out.print("Enter the number: ");
num1 = input.nextInt();
System.out.printf("The equation is %d ^ 2 = %.0f %n",num1,Math.pow(num1, 2));
break;
default:
System.out.println("Invalid Value!!");
}
System.out.print("Enter any character: ");
char myChar=input.next().charAt(0);
switch (Character.toLowerCase(myChar)){
case 'a':
case 'i':
case 'e':
case 'u':
case 'o':
System.out.printf("%c is vowel!!",myChar);
break;
default:
System.out.printf("%c is normal character!!", myChar);
}
input.close();
}
}
/*_______________________________*/
//! The switch Statement:
/*
switch (Expression){ //? Expression data type is integer
case constant 1: //?constant 1 is integer
Action Statements;
break;
case constant 2: //?constant 2 is integer
Action Statements;
break;
...
default:
Action Statements;
}
*/
/*_______________________________*/