- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_14.java
More file actions
Latest commit
49 lines (44 loc) · 1.21 KB
/
Copy pathpractice_14.java
File metadata and controls
49 lines (44 loc) · 1.21 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
importjava.util.Scanner;
publicclasspractice_14 {
publicstaticvoidmain(String[] args) {
// Problem 1
// Syntax Error - int a = 7
intage = 78;
intyear_born = 2000-78; // Logical error
// System.out.println(6/0);
// Problem 2
try{
inta = 666/0;
}
catch (IllegalArgumentExceptione){
System.out.println("HeHe");
}
catch (ArithmeticExceptione){
System.out.println("Haha");
}
// Problem 3
booleanflag = true;
int [] marks = newint[3];
marks[0] = 7;
marks[1] = 56;
marks[2] = 6;
ScannerSc = newScanner(System.in);
intindex;
inti = 0;
while(flag && i<5){
try {
System.out.println("Enter the value of index");
index = Sc.nextInt();
System.out.println("The value of marks[index] is " + marks[index]);
break;
}
catch (Exceptione) {
System.out.println("Invalid Index");
i++;
}
}
if(i>=5){
System.out.println("Error");
}
}
}