1. Using Java
MINISTRY OF EDUCATION & HIGHER EDUCATION
COLLEGE OF SCIENCE AND TECHNOLOGY
KHANYOUNIS- PALESTINE
Lecture 8
Decision Making
Practices
2. Identify and correct the errors in each of the
following sets of code:
if ( gender == 1 )
System.out.println( "Woman" );
else;
System.out.println( "Man" );
while ( z >= 0 )
sum += z;
2Presented & Prepared by: Mahmoud R. Alfarra
Practice 1
3. Identify and correct the errors in each of the
following sets of code:
if ( age >= 65 );
System.out.println( "Age greater than or equal to 65" );
else
System.out.println( "Age is less than 65 )";
int x = 1, total;
while ( x <= 10 ){
total += x;
++x; }
3Presented & Prepared by: Mahmoud R. Alfarra
Practice 1
4. Identify and correct the errors in each of the
following sets of code:
while ( x <= 100 )
total += x;
++x;
while ( y > 0 )
{
System.out.println( y );
++y; }
4Presented & Prepared by: Mahmoud R. Alfarra
Practice 1
5. Trace the following program, assuming x =5, y = 8
and x=8, y=5:
5Presented & Prepared by: Mahmoud R. Alfarra
Practice 2
6. Determine the output for each of the given sets of
code when x is 9 and y is 11 and when x is 11 and y is 9.
6Presented & Prepared by: Mahmoud R. Alfarra
Practice 2
7. Determine the output for each of the given sets of
code when x is 9 and y is 11 and when x is 11 and y is 9.
7Presented & Prepared by: Mahmoud R. Alfarra
Practice 2