Screen output
As we know, System.out.println()
outputs what is inside the ()
. To do the exercises, we want to expand on that. Firstly, here’s some code:
String name = "James"; // line 1int age = 23; // line 2 double salary = 50_000.0; // line 3 String out = "Details: " + name + ", " + age + ", " + salary;//line 4 System.out.println(out); // line 5
Line 1 declares a string literal "James"
and initializes the name
variable with it. A string literal is a sequence of characters (including numbers), enclosed in double quotes. We will discuss the String
class in detail in Chapter 12.
Lines 2 and 3 should be fine. We are declaring an int
type called age
and a double
type called salary
and using literal values to initialize them. The underscore used in line 3, enables us to make large...