-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaExp.java
More file actions
130 lines (99 loc) · 3.09 KB
/
LambdaExp.java
File metadata and controls
130 lines (99 loc) · 3.09 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.io.NotActiveException;
import java.util.InputMismatchException;
import java.util.Scanner;
interface A {
void disp();
}
class LambdaExp{
public static void main(String[] args) {
A obj = new A() {
public void disp()
{
System.out.println("This Function is Work Perfecly");
}
};
obj.disp();
}
}
// Exception Handling
// 1. Input Mismatch Exception
class ExpHadling1{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
try {
int a = scan.nextInt();
}
catch (InputMismatchException a) {
System.out.println(a);
}
}
}
// 2. Arithmetic Exception
class ExpHadling2{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
try {
System.out.println("Input Number : ");
int Y = 10/2;
}
catch (ArithmeticException Y) {
System.out.println(Y);
}
}
}
// Write a program that take two integers as input and Perform Division
// Arithmetic Exception for Division By "10/0" Zero.
// Input Mismatch Exception if the user input a Non - integer value
class ExpQ2{
public static void main(String[] args) {
Scanner val = new Scanner(System.in);
System.out.println("Enter Num 1 : ");
int a = val.nextInt();
System.out.println("Enter Num 2 : ");
int b = val.nextInt();
System.out.println();
int c = 0;
try {
c = a/b;
System.out.println(" Divison of Num 1 / Num 2 : " +c);
}
catch (ArithmeticException e){
System.out.println("Arithmetic Exception error, Plese Chcek your input ");
}
catch (InputMismatchException e){
System.out.println("Arithmetic Exception error, Plese Chcek your input ");
}
}
}
// Custom Exception Handling
class NotValidExp extends Exception{
public NotValidExp(String s)
{
super(s);
}
}
class CosExpHand{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
try {
System.out.println("Enter Age : ");
int age = scan.nextInt();
if (age < 18)
{
throw new NotValidExp("Your age Should Be above 18 ");
}
else
{
System.out.println(" Your age higher than 18");
}
}
catch (NotValidExp e)
{
System.out.println(e);
}
catch (Exception e)
{
System.out.println(e);
}
}
}