CSI 250 Lab Exercises, Fall 2011

American University of Science and Technology · Computer Programming II · 3 pages

All CSI 250 files
CSI 250 Lab Exercises, Fall 2011, page 1

Stuck on a question? A tutor can walk you through it.

CSI 250 Lab Exercises, Fall 2011, page 2 CSI 250 Lab Exercises, Fall 2011, page 3

More CSI 250 files

Show the text of this lab
American University of Science & Technology Faculty of Arts and Sciences Department of Computer Science CSI250L / ICT311L – Programming II Lab Fall 2015/2016 Lab Work 1 Part 1 - Introduction I. Introduction to the Programming II Lab (CSI250L / ICT 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("CSI250L/ICT311L Session1"); System.out.println("Fall 2015/2016"); } } 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 of the following shapes on the screen using "println" and the "for loop" statements. # ## ### #### ##### ###### ####### &&&&&&& &&&&&& &&&&& &&&& &&& && & * * * * * * * * * * * * * * * * * * * * * * * * 3