Core Java | Different Methods for Formatting String and Format Specifiers

Pubblicato il: 26 September 2022
sul canale di: Learn with Professor
822
like

Core Java | Different Methods for Formatting String and Format Specifiers
#corejava #tamilkaruvoolam #stringformat

Source Code:
class Employee{
private String name;
private Double salary;
public Employee(String name, Double salary) {
this.name = name;
this.salary = salary;
}
@Override
public String toString(){
return "Employee[Name: %s, Salary: %.2f]".formatted(name, salary);
//return String.format("Employee[Name: %s, Salary: %.2f]", name, salary);
//return "Employee[Name: "+name+", Salary: "+salary+"]";
}
}
public class EmployeeTest {
public static void main(String[] args) {
Employee emp = new Employee("Kumar", 123456.543);
System.out.println(emp.toString());
/**
String - %s
Integer - %d
Double / Float - %f / %.2f
Boolean - %b
*/
System.out.format("Employee Salary is %.2f", 7452754.5067);
}
}


In questa pagina del sito puoi guardare il video online Core Java | Different Methods for Formatting String and Format Specifiers della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Learn with Professor 26 September 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 822 volte e gli è piaciuto like spettatori. Buona visione!