CSI 311L Lab 1, Spring 2012
American University of Science and Technology · Java Programming Laboratory · 3 pages · Dr. Saeed Raheel
More CSI 311L files
Show the text of this lab
American University of Science & Technology
Department of Computer Science
CSI 311L – Java Programming Lab
Spring 2011/2012
Lab Work 1
Part 1 - Introduction to the CSI 311L
I.
Introduction to the JAVA Programming Lab (CSI 311L) objectives and
requirements.
II.
Explanation of the lab policies and procedures, as well as the Lab Syllabus and
grading policy. (Read and explain the Syllabus in details)
III.
Students will learn how to create and save a new java application by applying the
following steps:
1. Open a new text file using Notepad.
2. Save the file as "Exercise1.java".
3. Type the following java application
public class Exercise1
{
public static void main(String args[])
{
System.out.println("CSI 311L session1");
System.out.println("Fall 2011/2012");
}
}
4. Type "javac Exercise1.java" on the DOS prompt to compile the program.
5. Type "java Exercise1" on the DOS prompt to execute the program.
6. Ask the student to type system.out.println(“good luck”); at the end of
the main method.
7. Ask the students to repeat step 4. Show them how to correct the
compilation errors till they are able to execute the program.
1
Part 2 - What is the output of the following programs?
public class display1
{
public static void main(String args[])
{
int x =2, y=3;
System.out.println("x = "+x+"\ny = "+y);
x+=y;
y--;
System.out.printf("x = %d \ny = %d\n",x,y);
for(int i=0;i<x;i++)
{
for(int j=0;j<x;j++)
System.out.print("*");
System.out.println();
}
}
}
public class display2
{
public static void main(String args[])
{
int A =10, B=5;
System.out.println("the even numbers between 1 and A are:");
for(int i=1;i<=A;i++)
if(i%2==0)
System.out.print(i + "\t");
System.out.println();
int sum=0;
int c = (A+B)/2;
System.out.printf("c = %d\n",c);
int lc=1;
while(lc<= c)
{
if(lc%2 !=0)
sum+=lc;
lc++;
}
System.out.printf("the sum of odd numbers between 1 and c are: %d\n",sum);
}
}
2
Part 3 – Write simple java applications:
Write a java application to output each the following shapes on the screen using
"println" and the "for loop" statements.
#
##
###
####
#####
######
#######
&&&&&&&
&&&&&&
&&&&&
&&&&
&&&
&&
&
* * * * * * *
*
*
*
*
*
*
*
*
*
*
* * * * * * *
3