Java How to Program, Early Objects (11th Global Edition) - Does NOT include MyLab Programming
Java How to Program, Early Objects (11th Global Edition) - Does NOT include MyLab Programming
11th Edition
ISBN: 9780134800301
Author: Harvey Deitel, Paul J. Deitel
Publisher: Pearson Global Edition
Expert Solution & Answer
Book Icon
Chapter 4, Problem 6.1E

Explanation of Solution

Given code:

//Declare the variables

int x = 1, total;

//Execute "while" loop

while (x <= 10)

{

    //Perform calculation

    total += x;

    //Increment "x" by "1"

    ++x;

}

Error:

In the given code, the variable “total” is not initialized to perform the calculation.

Corrected code:

//Declare and initialize the variable

int x = 1, total=0;

//Execute "while" loop

while (x <= 10)

{

    //Per...

Explanation of Solution

Given code:

//Execute "while" loop

while (x <= 100)

    //Perform calculation

    total += x;

    //Increment "x" by "1"

    ++x;

Error:

In the given code, the body of “while” is not properly enclosed.

Corrected code:

//Execute "while" loop

while (x <= 100)

{

    //Perform calculation

    total += x;

    //Increment "...

Explanation of Solution

Given code:

//Execute "while" loop

while (y > 0)

{a

    //Print the value of "y"

    System.out.println(y);

    //Increment "y" by "1"

    ++y;

Error:

  • In the given code, the body of “while” is not properly enclosed.
  • The letter “a” given after opening brace “{” is not related to any syntax and it leads to an error.

Corrected code:

//Execute "while" loop

while (y > 0)

{

    //Print the value of "y"

    System.out...

Blurred answer
Students have asked these similar questions
CFG: Example 1 • Draw the CFG for the following code: int f(int n){ } int m = n* n; if (n < 0) else return 0; return m;
void main (void) { char result = a; for (char i = { 10; i > 5; i = i-1) result = result + i; } // point B } Consider the code above. What is the decimal value of "result" at "point B" if the variable "a" is initially 59?
#include using namespace std; const int y = 1; int main () { int static y = 2; int i = 3, j = 4, m = 5, n = 6; %3D int a = [] (int x, int i = 1) { return x * i; } (y, 3) ; %3D int b = [=] (int x) { return [=] (int b) { return b + j; } (x) % 7; } (a); int c = [=] (int x) mutable ->int { m = 6; return [6] (int j) mutable { y = a * b; return y / j; } (x) -m; } (b) ; cout << a << endl; cout << b << endl; cout << c << endl; cout << m << endl; cout << y < endl; return 0; This program outputs 5 lines. What are they? Please explain your work and your answer.

Chapter 4 Solutions

Java How to Program, Early Objects (11th Global Edition) - Does NOT include MyLab Programming

Ch. 4 - State whether each of the following is true or...Ch. 4 - State whether each of the following is true or...Ch. 4 - State whether each of the following is true or...Ch. 4 - Prob. 2.6SRECh. 4 - State whether each of the following is true or...Ch. 4 - Prob. 2.8SRECh. 4 - State whether each of the following is true or...Ch. 4 - State whether each of the following is true or...Ch. 4 - Write four different Java statements that each add...Ch. 4 - Write Java statements to accomplish each of the...Ch. 4 - Write Java statements to accomplish each of the...Ch. 4 - Write Java statements to accomplish each of the...Ch. 4 - Write Java statements to accomplish each of the...Ch. 4 - Write a Java statement to accomplish each of the...Ch. 4 - Write a Java statement to accomplish each of the...Ch. 4 - Write a Java statement to accomplish each of the...Ch. 4 - Write a Java statement to accomplish each of the...Ch. 4 - Combine the statements that you wrote in Exercise...Ch. 4 - Determine the value of the variables in the...Ch. 4 - Identify and correct the errors in each of the...Ch. 4 - What is wrong with the following while statement?...Ch. 4 - Compare and contrast the if single-selection...Ch. 4 - Explain what happens when a Java program attempts...Ch. 4 - Describe the two ways in which control statements...Ch. 4 - What type of iteration would be appropriate for...Ch. 4 - What is the difference between preincrementing and...Ch. 4 - Prob. 6.1ECh. 4 - What does the following program print? 1. //...Ch. 4 - 1. Read the problem statement. 2. Formulate the...Ch. 4 - 1. Read the problem statement. 2. Formulate the...Ch. 4 - 1. Read the problem statement. 2. Formulate the...Ch. 4 - 1. Read the problem statement. 2. Formulate the...Ch. 4 - (Find the Largest Number) The process of finding...Ch. 4 - Prob. 13.1ECh. 4 - (Find the Two Largest Numbers) Using an approach...Ch. 4 - Prob. 15.1ECh. 4 - What does the following program print? 1. //...Ch. 4 - What does the following program print? 1. //...Ch. 4 - (Dangling-else Problem) The Java compiler always...Ch. 4 - (Another Dangling-else Problem) Based on the...Ch. 4 - (Another Dangling-else Problem) Based on the...Ch. 4 - Prob. 21.1ECh. 4 - (Palindromes) A palindrome is a sequence of...Ch. 4 - (Printing the Decimal Equivalent of a Binary...Ch. 4 - (Checkerboard Pattern of Asterisks) Write an...Ch. 4 - (Multiples of 2 with an Infinite Loop) Write an...Ch. 4 - (Whats Wrong with This Code?) What is wrong with...Ch. 4 - Prob. 27.1ECh. 4 - (Sides of a Right Triangle) Write an application...Ch. 4 - Prob. 29.1ECh. 4 - Write an application that estimates the value of...Ch. 4 - Write an application that computes the value of e...Ch. 4 - (Enforcing Privacy with Cryptography) The...Ch. 4 - (World Population Growth) World population has...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr