-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_14.java
More file actions
49 lines (44 loc) · 1.21 KB
/
practice_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
import java.util.Scanner;
public class practice_14 {
public static void main(String[] args) {
// Problem 1
// Syntax Error - int a = 7
int age = 78;
int year_born = 2000-78; // Logical error
// System.out.println(6/0);
// Problem 2
try{
int a = 666/0;
}
catch (IllegalArgumentException e){
System.out.println("HeHe");
}
catch (ArithmeticException e){
System.out.println("Haha");
}
// Problem 3
boolean flag = true;
int [] marks = new int[3];
marks[0] = 7;
marks[1] = 56;
marks[2] = 6;
Scanner Sc = new Scanner(System.in);
int index;
int i = 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 (Exception e) {
System.out.println("Invalid Index");
i++;
}
}
if(i>=5){
System.out.println("Error");
}
}
}