FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/user.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
/
user.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (46 loc) · 1.32 KB
Breadcrumbs
Java-Programs
/
user.java
Copy path
File metadata and controls
46 lines (46 loc) · 1.32 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
import
java
.
util
.
Scanner
;
class
MyException
extends
Exception
{
private
int
age
;
MyException
(
int
a
) {
age
=
a
;
}
public
String
toString
() {
return
(
"Age: "
+
age
+
" is not within the valid range [10 to 105 years]"
);
}
}
public
class
user
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
String
name
;
int
age
;
boolean
valid
;
void
input
()
throws
MyException
{
System
.
out
.
println
(
"Enter user's name"
);
name
=
sc
.
nextLine
();
System
.
out
.
println
(
"Enter user's age"
);
age
=
Integer
.
parseInt
(
sc
.
nextLine
());
if
(
age
<
10
||
age
>
105
)
throw
new
MyException
(
age
);
if
(
age
>=
18
)
valid
=
true
;
}
void
display
(
user
ob
[]) {
System
.
out
.
println
(
"NAME AGE VALID"
);
for
(
int
i
=
0
;
i
<
ob
.
length
;
i
++) {
System
.
out
.
println
(
ob
[
i
].
name
+
" "
+
ob
[
i
].
age
+
" "
+
ob
[
i
].
valid
);
}
}
public
static
void
main
(
String
[]
args
) {
user
u
[] =
new
user
[
10
];
for
(
int
i
=
0
;
i
<
u
.
length
;
i
++) {
u
[
i
] =
new
user
();
try
{
u
[
i
].
input
();
}
catch
(
MyException
e
) {
System
.
out
.
println
(
e
);
System
.
out
.
println
(
"Enter the details again"
);
i
--;
}
}
u
[
0
].
display
(
u
);
}
}
Back
|
FazBrowse Home
|
New Git URL