Complete the statement to produce the following output.
Output the value of the variable userNum, not the literal 46.
Hint: Typing "I have 46 books." is a common mistake, as is "I have userNum books.". See above section for how to output a variable's value.
I have 46 books.
System.out.print( );
CodePudding user response:
System.out.println("I have " userNum " books.");
CodePudding user response:
It is possible to do more than one method
First Solution ,Can used println as like the below Example:
System.out.println("I have " userNum " books");
Second Solution , Can used printf as like the below Example:
System.out.printf("I have %d books",userName);
Note : To explain the two solution
println is short for "print line", meaning after the argument is printed then goes to the next line
printf is short for print formatted.
- %s formats strings.
- %d formats decimal integers.
- %f formats floating-point numbers.
- %t formats date/time values.
