-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameterized.java
More file actions
37 lines (31 loc) · 964 Bytes
/
Copy pathparameterized.java
File metadata and controls
37 lines (31 loc) · 964 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
//write a program in java using a parameterized constructor to print name, roll no and prn of user using scanner sc (input from the user)
import java.util.Scanner;
class Student {
String name;
int rollno;
int prn;
Student(String n, int r, int p) {
name = n;
rollno = r;
prn = p;
}
void display() {
System.out.println("Name: " + name);
System.out.println("Roll No: " + rollno);
System.out.println("PRN: " + prn);
}
}
public class parameterized {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name:");
String name = sc.nextLine();
System.out.println("Enter the roll no:");
int rollno = sc.nextInt();
System.out.println("Enter the prn:");
int prn = sc.nextInt();
Student s = new Student(name, rollno, prn);
s.display();
sc.close();
}
}