-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.java
More file actions
40 lines (31 loc) · 990 Bytes
/
student.java
File metadata and controls
40 lines (31 loc) · 990 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
37
38
39
40
import java.util.Scanner;
class Student {
String name;
String city;
int age;
void addData() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
name = sc.nextLine();
System.out.print("Enter city: ");
city = sc.nextLine();
System.out.print("Enter age: ");
age = sc.nextInt();
}
void printData() {
System.out.println("Name: " + name);
System.out.println("City: " + city);
System.out.println("Age: " + age);
}
public static void main(String[] args) {
Student s1 = new Student();
System.out.println("Enter details for Student 1:");
s1.addData();
System.out.println("Details of Student 1:");
s1.printData();
System.out.println("Enter the details of Student 2:");
s1.addData();
System.out.println("Details of Student 2:");
s1.printData();
}
}