Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
11th Edition
ISBN: 9780134743356
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4, Problem 6.1SRE
Combine the statements that you wrote in Exercise 4.5 into a Java application that calculates and prints the sum of the integers from 1 to 10. Use a while statement to loop through the calculation and increment statements. The loop should terminate when the value of x becomes 11.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
True or False
___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not.
___(5) In Java a while loop can be changed to a for loop and vice versa.
___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2
Exercise 1 : Write a Java program that computes the sum of even numbers less than or equal to n where n is given by the user (without nesting the control statements).
Exercise 2 : Write a Java application that computes the sum of even numbers and the product of odd numbers that are in the range [a, b] where a and b are given by the user (without nesting the control statements, to do so you have to use 2 separate loops).
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++;
}
Chapter 4 Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Ch. 4 - Fill in the blanks in each of the following...Ch. 4 - Fill in the blanks in each of the following...Ch. 4 - Fill in the blanks in each of the following...Ch. 4 - Fill in the blanks in each of the following...Ch. 4 - Prob. 1.5SRECh. 4 - Fill in the blanks in each of the following...Ch. 4 - Fill in the blanks in each of the following...Ch. 4 - Fill in the blanks in each of the following...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 - 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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify the temperature conversion program to print a heading above the table.
C Programming Language
Repeat any of the previous Practice Programs using JOptionPane, which is described in the graphics supplement a...
Java: An Introduction to Problem Solving and Programming (7th Edition)
Markup Write a program that asks the user to enter an items wholesale cost and its markup percentage. It should...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Using an example of a component that implements an abstract data type such as a stack or a list, show why it is...
Software Engineering (10th Edition)
(Display a running fan) Write a program that displays a running fan, as shown in Figure 15.35c. Use the Pause, ...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
What is denormalization?
Database Concepts (7th 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
- Modify the Eggs program to create a new one named Eggslnteractive that prompts the user for and accepts a number of eggs for each chicken.arrow_forwardWhat are the three parts of a for loop control? Write a for loop that prints the number from 1 to 100. (java)arrow_forwardWrite pseudocode for a Python program that uses iteration to guess a number from 1 to 10 that matches the computer’s number. Enter a name, the computer selects a number, users guess a number, and they keep guessing until they correctly guess the computer’s number. Turn in the pseudocode, Python program, and a screenshot of your output. Step 1: Ask the player to enter a name or quit to exit Step 2: use a while statement to test when the name is not equal to quit Step 3: input enter a number from 1 to 10 for the variable your_guess # display the number guessedprint("Your number is", your_guess) while num != your_guess: Step 4: Write an if statement for your_guess is less than num Step 5 display text with your guess and You won, name Step 6 ask the player to enter a name or quit to exitarrow_forward
- Write a Java application that computes the sum of even numbers and the product of odd numbers that are in the range [a, b] where a and b are given by the user (without nesting the control statements, to do so you have to use 2 separate loops).arrow_forwardWrite a loop that will print the numbers from 0 to 1000 in steps of 50. When the number is 800 or higher, it should break out of the loop. (Use Java)arrow_forwardThis is the question: only using the "while loop" Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 upto age. Write a java program that will print first 10 multiples of 3 in a single line.arrow_forward
- Using a while loop, write a Java program that promps the user to input two positive integers: firstNum and secondNum (firstNum must be smaller than secondNum). Output all the even numbers between firstNum and secondNum inclusive. Output all the odd numbers between firstNum and secondNum inclusive. Must do input validation. First number has to be smaller than the second number.arrow_forwardA Prime Number, is a number that can be divided evenly only by 1, or itself. Write a Java program, that prompts the user toenter a number, and determines if it is a prime or not. Use while-do looparrow_forwardHello This question is related to JAVA Print the even numbers from 1 to 100 using loops. (Hint: you can use break/continue) Kindly answer without handwritingarrow_forward
- Convert the following while loop into for loop : int x =0; while(x <=10) { System.out.println("X : " + x); x+=2; } note : a java codearrow_forwardA Java for loop has the following general form: for(start; test; increment) { statements } in the parentheses after the keyword "for", _____ provides the starting point for the loop, _____tells what to adjust before the next loop iteration, and _____ is a boolean expression that when true, lets the loop to continue and when false, causes the loop to terminate.arrow_forwardWrite a complete Java program using a while loop structure, name your program Q2. The program prompts the user to enter a series of names, and enters "1" to stop the loop. Output the total number of names entered using a System.out statement. Your sentinel value is "1".arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Control Structures - while loop - do-while loop - for loop - Goto - break - continue statements; Author: EzEd Channel;https://www.youtube.com/watch?v=21l11_9Osd0;License: Standard YouTube License, CC-BY