Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Identify and correct the errors in each of the following pieces of code. [Note:

ID: 3669485 • Letter: I

Question

Identify and correct the errors in each of the following pieces of code. [Note: There may be

more than one error in each piece of code.] Students do not have to run the code, but need to correct the code and comment what the error was and why.

if ( age >= 65 );

System.out.println( "Age is 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;

}

c)   while ( x <= 100 )

total += x;

++x;

d)   while ( y > 0 )

      {

System.out.println( y );

++y;

Explanation / Answer

a.//Wrong is if statement closed with semicolon with out using statements

ans

if ( age >= 65 )

{

System.out.println( "Age is greater than or equal to 65" );

       } else{

System.out.println( "Age is less than 65 )";

}

b. //in this code total value could not assing to varabile so assingn some value to total

ans

int x = 1, total=0 ;

while ( x <= 10 )

{

Total += x;

//if you want print use print here

++x;

}

c.// in here x value count assign to pass loop so

ans

int x=1

while ( x <= 100 ){

total += x;

++x;

}

d. //declare y and assign value to y

int y=1;

while ( y > 0 )

      {

System.out.println( y );

++y;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote