Java Lab Tutorial 05
Java Lab Tutorial 05
Objectives:
After the completion of this lab, students should be able to:
Use print statements (System.out.println and System.out.print) to
display texts and characters on the output console (screen).
Use the escape sequence characters with string literals.
Edit, compile, and run a simple Java programs using NetBeans IDE.
Find and fix common programming errors (e.g., syntax and logic).
Follow the coding style guidelines taught in lecture.
Use debugging tool provided by NetBeans IDE (presented in JavaLab01).
Lab Exercises:
Problem Description:
Write a Java program (Greeting1.java) that displays the lines of text shown in the
sample output using multiple print statements along with the appropriate escape
sequence characters (special characters).
Sample output:
"Welcome to Java"
\Hello Java World!\
Programming is fun!
\\Java is more fun\\
Problem Description:
Write a Java program (Greeting2.java) that displays the line of text shown in the
sample output using multiple print statements.
Sample output:
Problem Description:
Write a Java program (Greeting 3.java) that displays multiple lines of text shown
in the sample output using a single print statement along with the newline escape
character.
Sample output:
Welcome
To
Java
Programming
Language!
Problem Description:
Write a Java program (Shapes.java) that displays shapes (patterns) shown in the
sample output using asterisks (*). Use a single print statement for each line of output.
Sample output:
* ** * * * ***** * *
* * **** ** * *
* * *** *** * *
* * ** **** * *
* * * * ** * ***** **********
Problem Description:
The program (Arithmetic.java) presented below does not compile. You should find
and fix all the syntax and logic errors so that the program will successfully compile
and work. Once the program compiles, run the program, and compare its output with
the shown sample output.
Sample output:
Broken Code:
/
This program demonstrates a debugging problem.
*/
public class Arithmetic {
Public static void main (String[] args)
int num1 == 10
int num2 == 15
int num3 == 35
Modify the program to include the below arithmetic expression and a print statement
that displays the result of this expression:
10.5 5 + 𝑛𝑢𝑚1 × 𝑛𝑢𝑚2
exp = + × 12
𝑛𝑢𝑚3 𝑛𝑢𝑚3 − 𝑛𝑢𝑚1
Use the debugging tool provided by NetBeans IDE to debug your program.