Printing Strings and Primitive types
This exercise demonstrates how print statements execute, and it shows the precedence and purpose of the + operator with operands of different types.
Download files: PrintStatements.java
Areas: Primitive types.
|
|
PrintStatements.java |
|
|
| Question 1 |
| What does the command System.out.println do? |
| Question 2 |
| What is the output of the code excerpt? |
| Question 3 |
| The + operator is used in both line 3 and line 4. Is there any difference in the use of the + operator in these two lines of code? |
| Question 4 |
| Observe the following statement: System.out.println("m + n: " + (m + n)); Why is the rightmost m + n enclosed in parentheses? What will the output be if the brackets are removed? |
| Question 5 |
| Suppose we change the modified print statement in the previous question
further by
exchanging the position of the String and the numerical expression as follows: System.out.println( m + n + "m + n: "); What will be printed in this case? |
