Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (36 loc) · 1.14 KB

File metadata and controls

47 lines (36 loc) · 1.14 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package constructor;
public class Employee {
// question no 10 lvl 1
String name;
int EOJ;
long salary;
String address;
// Static flag to track if the header has been printed
static boolean headerPrinted = false;
Employee(){
}
Employee(String name, int EOJ, long salary, String address){
this.name = name;
this.EOJ = EOJ;
this.salary = salary;
this.address = address;
}
void display() {
//System.out.printf("| %-8s | %-10s | %-8s | %-10s | %n","Name","Year of joining","Salary","Address");
// Print the header only if it hasn't been printed yet
if (!headerPrinted) {
System.out.printf("| %-8s | %-10s | %-8s | %-10s | %n","Name","Year of joining","Salary","Address");
headerPrinted = true;
}
// prints the employee information
System.out.printf("| %-8s | %-15s | %-8s | %-10s | %n",name,EOJ,salary,address);
}
public static void main(String[] args) {
Employee e = new Employee("Robert",1994,15000,"ktm");
Employee e1 = new Employee("Sam",2000,20000,"Bkt");
Employee e2 = new Employee("John",1999,25000,"Pkr");
e.display();
e1.display();
e2.display();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.