forked from amanss00/ForNewbies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_of_objects.java
59 lines (41 loc) · 1002 Bytes
/
array_of_objects.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
57
58
59
import java.util.Scanner;
public class Student {
private String name;
private int age;
public void getdata()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Name : ");
name = sc.next();
System.out.println("Enter your age : ");
age = sc.nextInt();
}
public void display()
{
System.out.println("\nName : " +name);
System.out.println("Age : " +age);
}
}
//File 2 :-
import java.util.Scanner;
public class Records {
public static void main(String[] args) {
int rec;
Scanner sc1 = new Scanner(System.in);
System.out.println("How many Students do you want to Enter : ");
rec = sc1.nextInt();
Student[] s1 = new Student[rec];
for(int i = 0;i < rec;i++)
{
s1[i] = new Student();
}
for(int i = 0;i < rec;i++)
{
s1[i].getdata();
}
for(int i = 0;i < rec;i++)
{
s1[i].display();
}
}
}