Printouts

In this program you'll play around with System.out.print() and System.out.println() with various numbers, booleans, and messages.

  1. Go into the CS labs (see this map for details) and log onto a Windows machine.
  2. Start up a new project, called Prinouts, with a main class called Main.java. Refer to Lesson 2 if you are unsure how to do this. You do not need to include javabook2.jar in your class files. But be sure to delete TrivialApplication.java and set Main.java as the main file.
  3. In the blank file Main.java, write the following code:
  4. 
    public class Main {
    
    	public static void main(String[] args) {
    
    		String s = "Hello, World!";
    		System.out.println(s);                  // prints s on its own line
    
    		String t = "Computer Science is fun";
    		System.out.println(t);                  // prints t on its own line
    
    		System.out.print(s);                    // prints s
    		System.out.print(t);                    // prints t
    		System.out.println();                   // goes to a new line
    
    		System.out.println(s + t);              // prints st on its own line
    
    		int i = 6;
    		System.out.println("i = " + i);         // prints out i
    
    		double d = 6.0;
    		System.out.println("d = " + d);         // prints out d
    		
    		char c = '#';
    		System.out.println("c = " + c);         // prints out c
    
    		boolean b = true;
    		System.out.println("b = " + b);         // prints out b
    
    		Object o = new Object();
    		System.out.println("o = " + o);         // prints out o
    
    		// prints i, d, c, b, and o right next to each other
    		System.out.println(s + t + i + d + c + b + o);
    
    		// a useful debugging tactic
    		System.out.println("execution is now here");
    
    	}
    }
    
     
    
    
  5. Compile and run your program.
  6. Press enter, as the console window says, and the black console window will disappear.