Example Application: prints
There is no line break.
System.out.print("Simple Print - Hello World\n");It has line break.
System.out.println("Simple Println - Hello World");Format Specifier: %d
System.out.println("Print Number: " + 999);Format Specifier: %d
System.out.println("Print Long: " + 10L);Format Specifier: %c
charc = 'A';
System.out.println("Print Char: " + c);Format Specifier: %s
System.out.println("Print String: " + "String Value");Personperson = newPerson();
person.setName("Name");
person.setAge(30);
System.out.println("Print Class Model: " + person.toString());Use format specifier to replace with variable.
Stringformat = "Custom Format: [Number: %d] - [Text: %s] - [Person Name: %s, Person Age: %d]";
Object[] params = newObject[] { 999, "Simple text", person.getName(), person.getAge() };
System.out.println(String.format(format, params));Use format specifier to replace with variable.
Stringformat = "Custom Format: [Number: %d] - [Text: %s] - [Person Name: %s, Person Age: %d]";
Object[] params = newObject[] { 999, "Simple text", person.getName(), person.getAge() };
System.out.printf(format, params);See Java - Stringformat Specifiers
Format Specifier: %t
Datedate = newDate();
System.out.println("Date: "+ date);SimpleDateFormatdateFormatBR = newSimpleDateFormat("dd/MM/yyyy - hh:MM:ss");
System.out.println("Date BR: "+ dateFormatBR.format(date));System.out.println("Insert Text Here: ");
Scannerin = newScanner(System.in);
Stringtext = in.nextLine();
System.out.println("Keyboard text: " + text);