-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaConditionalStatements.java
More file actions
72 lines (60 loc) · 1.9 KB
/
JavaConditionalStatements.java
File metadata and controls
72 lines (60 loc) · 1.9 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
package flowControl;
import java.util.Scanner;
public class JavaConditionalStatements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input marks
System.out.print("Enter marks (0 to 100): ");
int marks = scanner.nextInt();
// 1. if condition (validity check)
if (marks < 0 || marks > 100) {
System.out.println("Invalid marks entered!");
return;
}
// 2. if-else condition (pass/fail)
if (marks >= 35) {
System.out.println("Status: Pass");
} else {
System.out.println("Status: Fail");
}
// 3. if-else-if ladder for grade
char grade;
if (marks >= 90) {
grade = 'A';
} else if (marks >= 75) {
grade = 'B';
} else if (marks >= 60) {
grade = 'C';
} else if (marks >= 45) {
grade = 'D';
} else if (marks >= 35) {
grade = 'E';
} else {
grade = 'F';
}
System.out.println("Grade: " + grade);
// 4. switch for remarks based on grade
switch (grade) {
case 'A':
System.out.println("Remark: Excellent");
break;
case 'B':
System.out.println("Remark: Very Good");
break;
case 'C':
System.out.println("Remark: Good");
break;
case 'D':
System.out.println("Remark: Average");
break;
case 'E':
System.out.println("Remark: Just Passed");
break;
default:
System.out.println("Remark: Fail");
}
// 5. Ternary operator for scholar label
String label = (marks >= 90) ? "Scholar" : "Regular";
System.out.println("Student Type: " + label);
}
}