Big Java, Binder Ready Version: Early Objects
Big Java, Binder Ready Version: Early Objects
6th Edition
ISBN: 9781119056447
Author: Cay S. Horstmann
Publisher: WILEY
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6, Problem 6RE

Explanation of Solution

a.

Given statements:

//declare the variables and assign the values

int i = 0;

int j = 10;

int n = 0;

//check "i" is less than "j"

while(i < j)

{   

    //increment the value

    i++;

    //decrement the value

    j--;

    //increment the value

    n++;

}

Trace table for the above loops:

ijn
0100
191
282
373
464
555

Explanation:

Here, the “i” value is “0”, “j” value is “10” and “n” value is “0”.

  • In first iteration of “while” loop checks “i < j” which means “0 < 10”. The condition becomes true, so it increment the “i” value, i = 1, decrement the “j” value, j = 9 and also increment the “n”, n = 1...

Explanation of Solution

b.

Given statements:

//declare the variables and assign the values

int i = 0;

int j = 0;

int n = 0;

//check "i" is less than "10"

while(i < 10)

{   

    //increment the value

    i++;

    //calculate the "n" value

    n = n + i + j;

    //increment the value

    j++;

}

Trace table for the above loops:

ijn
001
114
229
3316
4425
5536
6649
7764
8881
99100

Explanation:

Here, the “i” value is 0, “j” value is 0 and “n” value is 0.

  • In first iteration of “while” loop checks “i < 10” which means “0 < 10”. The condition becomes true, so it increment the “i” value, i = 1, calculate “n” value which means (0 + 1 + 0 = 1) and also increment the “j”, j = 1.
  • In second iteration of “while” loop checks “i < 10” which means “1 < 10”. The condition becomes true, so it increment the “i” value, i = 2, calculate “n” value which means (1+ 2 + 1 = 4) and also increment the “j”, j = 2.
  • In third iteration of “while” loop checks “i < 10” which means “2 < 10”. The condition becomes true, so it increment the “i” value, i = 3, calculate “n” value which means (4+ 3 + 2 = 9) and also increment the “j”, j = 3.
  • In fourth iteration of “while” loop checks “i < 10” which means “3 < 10”...

Explanation of Solution

c.

Given statements:

//declare the variables and assign the values

int i = 10;

int j = 0;

int n = 0;

//check "i" is greater than "0"

while(i > 0)

{   

    //decrement the value

    i--;

  //increment the value

    j++;

    //calculate the "n" value

    n = n + i - j;

}

Trace table for the above loops:

ijn
1008
9114
8218
7320
6420
5518
4614
378
280
19-10

Explanation:

Here, the “i” value is 10, “j” value is 0 and “n” value is 0.

  • In first iteration of “while” loop checks “i > 0” which means “10 > 0”. The condition becomes true, so it decrement the “i” value, i = 9, increment the “j”, j = 1 and calculate “n” value which means (0 + 9 - 1 = 8).
  • In second iteration of “while” loop checks “i > 0” which means “9 > 0”. The condition becomes true, so it decrement the “i” value, i = 8, increment the “j”, j = 2 and calculate “n” value which means (8 + 8 - 2 = 14).
  • In third iteration of “while” loop checks “i > 0” which means “8 > 0”. The condition becomes true, so it decrement the “i” value, i = 7, increment the “j”, j = 3 and calculate “n” value which means (14 + 7 - 3 = 18).
  • In fourth iteration of “while” loop checks “i > 0” which means “7 > 0”...

Explanation of Solution

d.

Given statements:

//declare the variables and assign the values

int i = 0;

int j = 10;

int n = 0;

//check "i" is greater than "0"

while(i != j)

{   

    //increment the "i" by 2

    i = i + 2;

  //decrement the "j" by 2

    j = j – 2;

    //increment the value

    n++;

}

Trace table for the above loops:

ijn
0100
281
462
643
824

...

Blurred answer

Chapter 6 Solutions

Big Java, Binder Ready Version: Early Objects

Ch. 6.3 - Write the for loop of the Investment class as a...Ch. 6.3 - Prob. 12SCCh. 6.3 - Prob. 13SCCh. 6.3 - Prob. 14SCCh. 6.3 - Prob. 15SCCh. 6.4 - Prob. 16SCCh. 6.4 - Prob. 17SCCh. 6.4 - Prob. 18SCCh. 6.4 - Prob. 19SCCh. 6.4 - Prob. 20SCCh. 6.5 - What does the SentinelDemo.java program print when...Ch. 6.5 - Prob. 22SCCh. 6.5 - Prob. 23SCCh. 6.5 - Prob. 24SCCh. 6.5 - Prob. 25SCCh. 6.6 - Prob. 26SCCh. 6.6 - Prob. 27SCCh. 6.6 - Prob. 28SCCh. 6.6 - Prob. 29SCCh. 6.6 - Prob. 30SCCh. 6.7 - What total is computed when no user input is...Ch. 6.7 - Prob. 32SCCh. 6.7 - Prob. 33SCCh. 6.7 - Prob. 34SCCh. 6.7 - Prob. 35SCCh. 6.7 - Prob. 36SCCh. 6.8 - Prob. 37SCCh. 6.8 - Prob. 38SCCh. 6.8 - Prob. 39SCCh. 6.8 - Prob. 40SCCh. 6.8 - Prob. 41SCCh. 6.9 - Prob. 42SCCh. 6.9 - Prob. 43SCCh. 6.9 - Prob. 44SCCh. 6.9 - Prob. 45SCCh. 6.9 - Prob. 46SCCh. 6.10 - In the debugger, you are reaching a call to...Ch. 6.10 - Prob. 48SCCh. 6.10 - Prob. 49SCCh. 6.10 - Prob. 50SCCh. 6.10 - Prob. 51SCCh. 6 - Prob. 1RECh. 6 - What do these loops print? int i - 0; int j -...Ch. 6 - What do these code snippets print? int result -...Ch. 6 - Write a while loop that prints All squares less...Ch. 6 - Write a loop that computes The sum of all even...Ch. 6 - Provide trace tables for these loops. int i = 0;...Ch. 6 - What do these loops print? for (int i = 1; i < 10;...Ch. 6 - What is an infinite loop? On your computer, how...Ch. 6 - Write a program trace for the pseudocode in...Ch. 6 - What is an “off-by-one” error? Give an example...Ch. 6 - What is a sentinel value? Give a simple rule when...Ch. 6 - Which loop statements does Java support? Give...Ch. 6 - How many iterations do the following loops carry...Ch. 6 - Write pseudocode for a program that prints a...Ch. 6 - Write pseudocode for a program that prints a...Ch. 6 - Write pseudocode for a program that reads a...Ch. 6 - Write pseudocode for a program that reads a...Ch. 6 - Rewrite the following for loop into a whi1e...Ch. 6 - Rewrite the following do loop into a while...Ch. 6 - Provide trace tables of the following loops. int s...Ch. 6 - What do the following loops print? Work out the...Ch. 6 - What do the following program segments print? Find...Ch. 6 - Prob. 23RECh. 6 - Add a storyboard panel for the conversion program...Ch. 6 - In Section 6.6, we decided to show users a list of...Ch. 6 - Change the storyboards in Section 6.6 to support a...Ch. 6 - Draw a flow chart for a program that carries out...Ch. 6 - Prob. 28RECh. 6 - Prob. 29RECh. 6 - The nested loops for (int i = 1; i <= height;...Ch. 6 - Suppose you design an educational game to teach...Ch. 6 - In a travel simulation, Harry will visit one of...Ch. 6 - Prob. 33RECh. 6 - Explain in detail how to inspect the string stored...Ch. 6 - Prob. 35RECh. 6 - Prob. 36RECh. 6 - Explain the divide-and-conquer strategy to get...Ch. 6 - Write a program that reads an initial investment...Ch. 6 - Write programs with loops that compute The sum of...Ch. 6 - Write programs that read a sequence of integer...Ch. 6 - Write programs that read a line of input as a...Ch. 6 - Complete the program in How To 6.1 on page 272....Ch. 6 - Write a program that reads a set of floating-point...Ch. 6 - Translate the following pseudocode for finding the...Ch. 6 - Translate the following pseudocode for randomly...Ch. 6 - Write a program that reads a word and prints each...Ch. 6 - Write a program that reads a word and prints the...Ch. 6 - Write a program that reads a word and prints the...Ch. 6 - Write a program that reads a word and prints all...Ch. 6 - Write a program that prints all powers of 2 from...Ch. 6 - Write a program that reads a number and prints all...Ch. 6 - Write a program that prints a multiplication...Ch. 6 - Write a program that reads an integer and...Ch. 6 - Write a program that reads an integer and...Ch. 6 - Currency conversion. Write a program that first...Ch. 6 - Write a program that first asks the user to type...Ch. 6 - Prob. 22PECh. 6 - Prob. 1PPCh. 6 - Prob. 2PPCh. 6 - The Fibonacci numbers are defined by the...Ch. 6 - Factoring of integers. Write a program that asks...Ch. 6 - Primenumbers. Write a program that prompts the...Ch. 6 - The game of Nim. This is a well-known game with a...Ch. 6 - Prob. 7PPCh. 6 - Prob. 8PPCh. 6 - Prob. 9PPCh. 6 - Prob. 10PPCh. 6 - Prob. 11PPCh. 6 - Prob. 12PPCh. 6 - Prob. 13PPCh. 6 - Prob. 14PPCh. 6 - Prob. 15PPCh. 6 - Prob. 17PPCh. 6 - Prob. 18PPCh. 6 - Prob. 19PPCh. 6 - Prob. 20PPCh. 6 - Prob. 21PPCh. 6 - Draw a picture of the “four-leaved rose” whose...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY