Purchase Solution

Java: flow of control looping

Not what you're looking for?

Ask Custom Question

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;
}

Purchase this Solution

Solution Summary

The solution not only provides the output of code execution, but it also explains why that output will come.

Solution Preview

Thank you for asking BrainMass!

1. The output of given code sequence would be below 5 lines. First line would be printed due to code before the loop. Loop will execute 2 times, one for user input 3, and second time for user input 5.

Enter an int >
Hello
Enter an int >
Hello
Enter an int >

2. Loop will execute for the values ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C++ Operators

This quiz tests a student's knowledge about C++ operators.