Рет қаралды 223
Core Java| print() Vs println() Vs prinf() | Know the difference
#tamilkaruvoolam #corejava #print
Source Code
import java.util.Scanner;
class Employee {
String name;
Double salary;
Employee(String name) {
this.name = name;
}
Employee(String name, Double salary) {
this(name);
this.salary = salary;
}
public Double getSalary() {
return salary;
}
public String toString() {
return "Employee [name=" + name + ", salary=" + salary + "]";
}
}
public class EmployeeTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Name: ");
String name = sc.nextLine();
System.out.print("Enter the Salary: ");
Double salary = sc.nextDouble();
sc.nextLine();
Employee employee = new Employee(name, salary);
System.out.println(employee.toString());
System.out.printf("%.3f", employee.getSalary());
}
}