CS110T Lab02 PDF
CS110T Lab02 PDF
Lab Objectives:
In this lab, the student will practice:
ü Creating, compiling and running a simple Java programs.
ü Using the output statements in Java: System.out.print and System.out.println
ü Defining variables of different data types
ü Debugging code.
L.Maram AlShablan
Lab Exercise 1: My First Program
Problem Description: Write a program that prints your name, your ID and “ I'm
studying Java “ message on a separate lines.
Code:
2
// Lab Exercise 2: Exercise2.java
// Defining variables of different data types
System.out.println("a+b="+a+b);
System.out.println(c+" is for Java");
System.out.println("Pseudocode is a " +isBoolean+ " computer
code");
}
}
Output :
3
Lab Exercise 3: Debugging
Problem Description: The following program does not compile. Fix all the compilation
errors so that the program will compile successfully (9 errors).
public Class
{
// main method begins execution of Java application
public static void main( string args[] );
{
system.out.println("Programming is","an exercise in learning how to
learn");
System.out.print(learning is never done without errors ")
Compilation errors:
4
Lab Exercise 4: Pascal Triangle
Problem Description: Write a Java program that prints the following Pascal Triangle.
5
Assignment Problems:
Problem Description:
1. Write a Java program that prints the following shape:
Problem Description:
2. What is the expected output of the following program:
Problem Description:
3. The following code segment does not compile. Fix all the compilation errors so that the
program will compile successfully.