CS108 Introduction to Java Programming

Laboratory Questions Chapter 1

Q1. Create a source program by copying the code below exactly as shown. Attempt to compile the program. Inspect the errors given by the compiler, and debug the program. Proceed until the program compiles and runs successfully. Compare the errors with the ones you discovered in the tutorial.

// /* programs need

comments */

class OneOne {

public static void main(String[] args) {

aString = new String("Well!");

2ndString = "Now!";

System.out.println("Isn't this an interesting program);

System.out.println("Answer yes or no!")

}

}

 

Q2. Write a program that produces the following output on screen:

This is my first try

at programming in Java.

It is fun!

Use three different strings to define the three lines of the message.

 

Q3. Write a program that produces the following output on screen:

This is my first try at programming in Java. It is fun!

Use three different strings to define the three lines of the message. (Use the method print() instead of println() where appropriate).

 

Q4. Write a program that produces the following output on screen (note the blank lines):

This is my first try

at programming in Java.

It is fun!