Computer Science Worksheet
Exercises on print and println

1. What will be displayed by the following Java statements?

int temperature = 42, pressure = 29;
System.out.println ("The temperature is " + temperature);
System.out.print ("and the barometric pressure is " + pressure);
System.out.println (" inches of mercury.");

 
 

2. What will be displayed by the following Java statements?

 int pressure = 29, temperature = 42;
 System.out.print ("The barometric pressure is " + pressure);
System.out.println (" and the temperature is " + temperature);
 System.out.println (" degrees.");
 
 
 

3. What will be displayed by the following Java statements?

 int width = 100, height = 40;
 System.out.print ("The width is " + width);
 System.out.println (" and the height is " + height);
 System.out.println (" feet.");
 
 
 
 

4. What will be displayed by the following Java statements?

 int width = 40, height = 80;
 System.out.println ("The height is " + height);
 System.out.print ("and the width is " + width);
 System.out.println (" inches.");