What are the values of i and sum after this code sequence


1. What is the output of this code sequence? (The user successively enters 3, 5, and -1.)

System.out.print( "Enter an int > " );
int i = scan.nextInt( );
while ( i !=-1 )
{
System.out.println( "Hello" );
System.out.print( " Enter an int > " );
i = scan.nextint ( );
}

2. what are the values of i and product after this code sequence is executed?

int i=6;
int product =1;
do
{
product *=i;
i++;
}while ( i <9 );

3. What is the output of this code sequence?

for ( int i = 0; i <3; i++ )
System.out.println( "Hello" );
System.out.println( " Done" );

4. What are the values of i and sum after this code sequence is executed?

int i = 0;
int sum = 0;
for ( i =0; i < 5; i++ )
{
sum += i;
}

5. What is the value of sum after this code sequence is executed?

int sum = 0;
for ( int i = 1; i < 10; i++ )
{
i++;
sum += i;
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What are the values of i and sum after this code sequence
Reference No:- TGS01249329

Now Priced at $20 (50% Discount)

Recommended (97%)

Rated (4.9/5)