FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/UserdefinedException.java at main · VirajPatidar/Java-Programs · GitHub
VirajPatidar
/
Java-Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
UserdefinedException.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (48 loc) · 1.45 KB
Breadcrumbs
Java-Programs
/
UserdefinedException.java
Copy path
File metadata and controls
48 lines (48 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
Scanner
;
class
ageException
extends
Exception
{
private
int
age
;
ageException
(
int
a
) {
age
=
a
;
}
public
String
toString
() {
return
(
"Age: "
+
age
+
" is not within the range"
);
}
}
public
class
UserdefinedException
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
String
name
;
int
age
=
0
;
int
flag
=
0
;
void
input
()
throws
ageException
{
System
.
out
.
println
(
"Enter name"
);
name
=
sc
.
nextLine
();
System
.
out
.
println
(
"Enter age"
);
age
=
Integer
.
parseInt
(
sc
.
nextLine
());
if
(
age
<
10
||
age
>
105
)
throw
new
ageException
(
age
);
}
void
display
(
UserdefinedException
ob
[]) {
System
.
out
.
print
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
ob
.
length
;
i
++) {
System
.
out
.
print
(
ob
[
i
].
name
+
" "
+
ob
[
i
].
age
+
" "
);
if
(
ob
[
i
].
age
>=
18
&&
ob
[
i
].
flag
!=
1
)
System
.
out
.
print
(
"valid
\n
"
);
else
System
.
out
.
print
(
"Invalid
\n
"
);
}
}
public
static
void
main
(
String
[]
args
) {
UserdefinedException
u
[] =
new
UserdefinedException
[
3
];
UserdefinedException
ob
=
new
UserdefinedException
();
for
(
int
i
=
0
;
i
<
u
.
length
;
i
++) {
u
[
i
] =
new
UserdefinedException
();
try
{
u
[
i
].
input
();
}
catch
(
ageException
e
) {
System
.
out
.
println
(
e
);
u
[
i
].
flag
=
1
;
}
}
ob
.
display
(
u
);
}
}
Back
|
FazBrowse Home
|
New Git URL