Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.1, Problem 3STQ
What output is produced by the following code?
int count = 0;
do
{
System.out. println(count);
count ++;
}
while(count < 0);
System.out.println(“count after loop = “ | count);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the number of times the following loop is executed?
for the value of b in (1,10):
a printout of b
The for loop in (a) is converted into the while loop in (b). What is wrong? Correct it. (java language)
(a)
int sum = 0;
for (int i = 0; i < 4; i++) {
if (i % 3 == 0) continue;
sum += i;
}
(b)
int i = 0, sum = 0;
while (i < 4) {
if (i % 3 == 0) continue;
sum += i;
i++;
}
What is the value in count after the following loop is executed?int count = 0;do {System.out.println("Eid Mubarak");} while (count++ < 8);System.out.println(count);
a)9
b)8
c)0
d)10
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Can the body of a while loop execute zero times?...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Revise the following code so that it uses a while...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Imagine a program that reads the population of a...Ch. 4.1 - Prob. 7STQCh. 4.1 - What output is produced by the following code? int...Ch. 4.1 - What output is produced by the following code? for...Ch. 4.1 - What output is produced by the following code? for...
Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - (Challenge) Repeat the previous project, but...Ch. 4 - Write a JavaFx application that displays a series...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
If c is a lowercase character, the expression C produces the uppercase equivalent of c, assuming an ASCII chara...
Programming in C
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
What is the distinction between application software and system software? Give an example of each.
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Convert the following while loop to a for loop: int count = 0; while (count 50) { System.out.println(count is ...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Days in Current Month Write a program that can determine the number of days in a month for a specified month an...
Starting Out with C++: Early Objects
Suppose the memory cells at addresses 0x00 through 0x09 in the Vole contain the following bit patterns: Address...
Computer Science: An Overview (12th Edition)
Knowledge Booster
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.Similar questions
- What, in your opinion, is wrong with this nested for loop? for(int x = 0; x < 10; x++){ for(int x = 10; x > 0; x--){ System.out.println(x); } }arrow_forwardWhat is the output for the following loop? int number; bool done; number = 2; done = FALSE; while (!done) { number = number * 2; if (number > 12) done = TRUE; cout << number << endl; }arrow_forwardThe following code is an example of what kind of loop? int count = 0; while (count < 10) { count++; }arrow_forward
- What is the output of the following?int count = 3;while (--count > 0)cout << count << " ";arrow_forwardCount and sum the same? yes or, no, why? 1. { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } } 2. { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } System.out.println("\nAfter the loop count is: " + count ); }arrow_forwardWhat is the output of the following (when embedded in a complete program)? int n = 5; while (--n > 0) { if (n ==2) break; cout<<n<<””; } cout<<”End of Loop.”;arrow_forward
- What are the differences between a while loop and a do-while loop? Convert the following while loop into a do-while loop: Scanner input = new Scanner(System.in);int sum = 0; System.out.println("Enter an integer "+"(the input ends if it is 0)");int number = input.nextInt(); while (number != 0) { sum += number; System.out.println("Enter an integer"+"(the input ends if it is 0)"); number = input.nextInt();}arrow_forwardWhat will this For loop will print on the screen? FOR x = 1 TO 5 Print x * x Next xarrow_forwardWhat is the exact output of the following nested loop? for (int row = 2; row < 10; row += 4) { int column =1; while (column <= 4) { System.out.print(row - column + " " ); column += 2; } System.out.println(); } 1 -1 5 3 1 -1 5 3 All of these are correct. 1 -1 5 3arrow_forward
- What is the exact output of the following nested for loop? for (int row = 1; row < 10; row += 4) { for (int column =1; column <= 5; column += 2) { System.out.print(row * column + " " ); } System.out.println(); } 1 3 5 5 15 25 9 27 45 All of the are correct. 1 5 9 3 15 25 5 25 45 1 5 9arrow_forward1. How many times does the following for loop execute? – for (i = 5; i >= 0; i--) System.out.println(i * i); 2. How many times does the following for loop execute? – for (i = 0; i <9; i = i + 2) System.out.println(i * i); 3. What is the output for the code fragment down below for (i = 1; i <= 3; i++){ for(j = 1; j <= 5; j++) { if (j % 2 == 0) {Print "*" } else {Print "-" } } System.out.println();}arrow_forwardWrite a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with newline Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 import java.util.Scanner; public class NumberPrompt {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int userInput; /* Your solution goes here */ System.out.println("Your number < 100 is: " + userInput);}}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY