0% found this document useful (0 votes)
15 views4 pages

Java Lab Tutorial 05

Uploaded by

jojohalabi660
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Java Lab Tutorial 05

Uploaded by

jojohalabi660
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 05 Introduction to Java

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:

Lab Exercise 1 – Multiple Text Lines with Multiple Statements

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\\

©2011 Dr. Abdulbaset Gaddah, < Computer Programming > [ 1]


Lab 05 Introduction to Java

Lab Exercise 2 – One Text Line with Multiple Statements

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:

Welcome to Java Programming Language!

Lab Exercise 3 – Multiple Text Lines with A Single Statement

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!

©2011 Dr. Abdulbaset Gaddah, < Computer Programming > [ 2]


Lab 05 Introduction to Java

Lab Exercise 4 – Drawing Shapes

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:

* ** * * * ***** * *
* * **** ** * *
* * *** *** * *
* * ** **** * *
* * * * ** * ***** **********

©2011 Dr. Abdulbaset Gaddah, < Computer Programming > [ 3]


Lab 05 Introduction to Java

Lab Exercise 5 – Debugging

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:

The sum is: 60


The product is: 5250
The average is: 20.0

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

int sum = num1 + num2 + num3;


int product = num1 * num2 * num3;
int average = num1 + num2 + num3 / 3.0;

system.out.println( "The sum is: " + Sum ),


system.out.println( "The product is: " + product ),
system.out.println( "The average is: + average ),
} // end main
} // end Arithmetic class

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.

©2011 Dr. Abdulbaset Gaddah, < Computer Programming > [ 4]

You might also like