-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1a.txt
67 lines (54 loc) · 1.51 KB
/
1a.txt
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
60
61
62
63
64
65
66
67
Create a Java class called Student with the following details as variables within it.
(i) USN
(ii) Name
(iii) Branch
(iv) Phone
Write a Java program to create n Student objects and print the USN, Name, Branch, and Phone of these objects with suitable headings.
import java.util.Scanner;
class Student
{
String USN, Name, Branch, Phone;
Scanner input = new Scanner (System.in);
void read()
{
System.out.println("Enter Student Details");
System.out.println("Enter USN");
USN = input.nextLine();
System.out.println("Enter Name");
Name = input.nextLine();
System.out.println("Enter Branch");
Branch = input.nextLine();
System.out.println("Enter Phone");
Phone = input.nextLine();
}
void display()
{
System.out.printf("%-20s %-20s %-20s %-20s", USN, Name, Branch,
Phone);
}
}
class Studentdetails
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter number of student details to be created");
int number = input.nextInt();
Student s[] = new Student[number];
// Read student details into array of student objects
for (int i = 0; i < number; i++)
{
s[i] = new Student();
s[i].read();
}
// Display student information
System.out.printf("%-20s %-20s %-20s %-20s", "USN", "NAME",
"BRANCH", "PHONE");
for (int i = 0; i < number; i++)
{
System.out.println();
s[i].display();
}
input.close();
}
}