-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerciseCBSE.java
More file actions
83 lines (68 loc) · 2.16 KB
/
ExerciseCBSE.java
File metadata and controls
83 lines (68 loc) · 2.16 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
import java.util.Scanner; // #include <iostream>
// Done
public class ExerciseCBSE {
public static void main(String [] args)
{
Scanner obj = new Scanner(System.in);
// with validation aswell
int total = 500; // as per code with harry
int marks1, marks2, marks3, marks4, marks5; // for simple declaration
System.out.println(" REMEMBER MARKS ARE OUT OF 100!");
System.out.print(" Enter subject no 1 marks : ");
boolean b1 = obj.hasNextInt();
if (b1)
{
marks1 = obj.nextInt();
}
else {
System.out.println(" NOT INTEGER!");
return; // termination
}
System.out.print(" Enter subject no 2 marks : ");
boolean b2 = obj.hasNextInt();
if (b2)
{
marks2 = obj.nextInt();
}
else {
System.out.println(" NOT INTEGER!");
return; // termination
}
System.out.print(" Enter subject no 3 marks : ");
boolean b3 = obj.hasNextInt();
if (b3)
{
marks3 = obj.nextInt();
}
else {
System.out.println(" NOT INTEGER!");
return; // termination
}
System.out.print(" Enter subject no 4 marks : ");
boolean b4 = obj.hasNextInt();
if (b4)
{
marks4 = obj.nextInt();
}
else {
System.out.println(" NOT INTEGER!");
return; // termination
}
System.out.print(" Enter subject no 5 marks : ");
boolean b5 = obj.hasNextInt();
if (b5)
{
marks5 = obj.nextInt();
}
else {
System.out.println(" NOT INTEGER!");
return; // termination
}
float obtained = marks1 + marks2 + marks3 + marks4 + marks5;
// System.out.println(obtained); // for self check
float percentage = (obtained/total) * 100;
// 250/500 == 0.5 which is 0 in integer that's why took float for obtained
System.out.println(" Percentage : " + percentage);
obj.close(); // closing scanner object as this is end now
}
}