-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.java
56 lines (55 loc) · 1.48 KB
/
run.java
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
import java.util.*;
class check{
String name;
int roll_call;
void accept(){
Scanner zx = new Scanner(System.in);
System.out.println("Enter your name:= ");
name = zx.nextLine();
System.out.println("Enter your roll number:= ");
roll_call = zx.nextInt();
}
class invalidname extends Exception{
invalidname(String str){
super(str);
}
}
class invalidroll extends Exception{
invalidroll(String str){
super(str);
}
}
void Checkname(){
int length = name.length();
try{
for (int i=0; i<length; i++ ){
if ((name.charAt(i)>=65 && name.charAt(i)<=90) || (name.charAt(i)>=97 && name.charAt(i)<=122)){}
else{
throw new invalidname("Name should have only aplhabets ");
}
}
}
catch(invalidname a){
System.out.println("Exception foound " +a);
}
}
void Checkrollnum(){
try{
if (roll_call<=23 && roll_call>=0){}
else{
throw new invalidroll("Roll number should be between 1 to 23");
}
}
catch(invalidroll a){
System.out.println("Exception found " +a);
}
}
}
class run{
public static void main(String[] args) {
check Student1 = new check();
Student1.accept();
Student1.Checkname();
Student1.Checkrollnum();
}
}