-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodsInClasss.java
More file actions
36 lines (35 loc) · 951 Bytes
/
MethodsInClasss.java
File metadata and controls
36 lines (35 loc) · 951 Bytes
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
//methods in classes:
import java.io.*;
import java.util.Scanner;
class person2
{
private String name;
private int age;
public void get_data()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Scanner key=new Scanner(System.in);
System.out.println("enter name=");
name=br.readLine(); //or name=key.nextLine();
System.out.println("enter age=");
age=Integer.parseInt(br.readLine());
}
public void put_data()
{
if(age<30)
System.out.println(name+" is young");
else if(age>=30 && age<50)
System.out.println(name+" is middle aged");
else
System.out.println(name+" is old");
}
}
public class MethodsInClasss
{
public static void main(String args[]) throws IOException
{
person2 obj=new person2();
obj.get_data();
obj.put_data();
}
}