Introduction To Programming Information Technology , 1’st Semester MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Using Java Introduction To Programming Information Technology , 1’st Semester Lecture 11 Repetition Statements Practices Teacher: Mahmoud Rafeek Alfarra
Practice 1 Identify and correct the errors in each of the following pieces of code. int x = 1, total; while ( x <= 10 ) { total += x; ++x; } Presented & Prepared by: Mahmoud R. Alfarra
Practice 1 Identify and correct the errors in each of the following pieces of code. while ( x <= 100 ) total += x; ++x; while ( y > 0 ) { System.out.println( y ); ++y; Presented & Prepared by: Mahmoud R. Alfarra
Practice 1 Identify and correct the errors in each of the following pieces of code. for ( i = 100, i >= 1, i++ ) System.out.println( i ); The following code should output the odd integers from 19 to 1: for ( i = 19; i >= 1; i += 2 ) Presented & Prepared by: Mahmoud R. Alfarra
Practice 1 Identify and correct the errors in each of the following pieces of code. The following code should print whether integer value is odd or even: switch ( value % 2 ) { case 0: System.out.println( "Even integer" ); case 1: System.out.println( "Odd integer" ); } Presented & Prepared by: Mahmoud R. Alfarra
Practice 1 Identify and correct the errors in each of the following pieces of code. The following code should output the even integers from 2 to 100: counter = 2; do { System.out.println( counter ); counter += 2 ; } While ( counter < 100 ); Presented & Prepared by: Mahmoud R. Alfarra
Practice 2 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 3 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 3 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 4 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 5 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 5 Trace the following program: Presented & Prepared by: Mahmoud R. Alfarra
Practice 6 Write an application that finds the smallest of several integers. Assume that the first value read specifies the number of values to input from the user. Presented & Prepared by: Mahmoud R. Alfarra
Practice 7 Write an application that calculates the product of the odd integers from 1 to 15. Presented & Prepared by: Mahmoud R. Alfarra
Practice 8 Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character. Maximize your use of repetition, and minimize the number of output statements. Presented & Prepared by: Mahmoud R. Alfarra
More practices in the text book, chapters 4 and 5 Presented & Prepared by: Mahmoud R. Alfarra
Emank X Mezank من أعظم الاسباب التي ترفع درجة الإيمان للعبـد أن: يتق الله Presented & Prepared by: Mahmoud R. Alfarra
Next… Practices Presented & Prepared by: Mahmoud R. Alfarra