Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.2, Problem 6SC
Hand-trace the following code, showing the value of n and the output.
int n = 5;
while (n >= 0)
{
n--;
System.out.print(n);
}
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
#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.
#include
int k=0;
int f(int t)
{
k += t;
heturn k;
}
void main()
{
int i, result=1;
for(i = 1;i <= 3;i++)
result = f(i);
printf("%d\n", result);
}
A 3
B
C) 1
D 123
Chapter 4 Solutions
Big Java Late Objects
Ch. 4.1 - How many years does it take for the investment to...Ch. 4.1 - If the interest rate is 10 percent per year, how...Ch. 4.1 - Modify the program so that the balance after each...Ch. 4.1 - Suppose we change the program so that the...Ch. 4.1 - What does the following loop print? int n = 1;...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, assuming that a is...Ch. 4.2 - Trace the following code. What error do you...Ch. 4.2 - Prob. 10SC
Ch. 4.3 - Write the for loop of the InvestmentTable.java...Ch. 4.3 - How many numbers does this loop print? for (int n...Ch. 4.3 - Write a for loop that prints all even numbers...Ch. 4.3 - Write a for loop that computes the sum of the...Ch. 4.3 - How would you modify the for loop of the...Ch. 4.4 - Prob. 16SCCh. 4.4 - Rewrite the input check do loop using a while loop...Ch. 4.4 - Suppose Java didnt have a do loop. Could you...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.5 - What does the SentinelDemo.java program print when...Ch. 4.5 - Why does the SentinelDemo.java program have to...Ch. 4.5 - What would happen if the declaration of the salary...Ch. 4.5 - In the last example of this section, we prompt the...Ch. 4.5 - Prob. 25SCCh. 4.6 - Prob. 26SCCh. 4.6 - Google has a simple interface for converting...Ch. 4.6 - Consider a modification of the program in Self...Ch. 4.6 - Prob. 29SCCh. 4.6 - Produce a storyboard for a program that compares...Ch. 4.7 - What total is computed when no user input is...Ch. 4.7 - Prob. 32SCCh. 4.7 - What are the values of position and ch when no...Ch. 4.7 - Prob. 34SCCh. 4.7 - Prob. 35SCCh. 4.7 - Prob. 36SCCh. 4.8 - Why is there a statement System.out.println(); in...Ch. 4.8 - How would you change the program to display all...Ch. 4.8 - Prob. 39SCCh. 4.8 - What do the following nested loops display? for...Ch. 4.8 - Prob. 41SCCh. 4.9 - Prob. 42SCCh. 4.9 - You need to write a program for DNA analysis that...Ch. 4.9 - Prob. 44SCCh. 4.9 - Consider the task of finding numbers in a string....Ch. 4.10 - How do you simulate a coin toss with the...Ch. 4.10 - How do you simulate the picking of a random...Ch. 4.10 - Why does the loop body in Dice.java call...Ch. 4.10 - Prob. 49SCCh. 4.10 - Prob. 50SCCh. 4 - Given the variables String stars = ""; String...Ch. 4 - What do these loops print? a. int i = 0; int j =...Ch. 4 - What do these code snippets print? a. int result =...Ch. 4 - Write awhile loop that prints a. All squares less...Ch. 4 - Write a loop that computes a. The sum of all even...Ch. 4 - Provide trace tables for these loops. a. int i =...Ch. 4 - What do these loops print? a. for (int i = 1; i ...Ch. 4 - What is an infinite loop? On your computer, how...Ch. 4 - Write a program trace for the pseudocode in...Ch. 4 - What is an off-by-one error? Give an example from...Ch. 4 - What is a sentinel value? Give a simple rule when...Ch. 4 - Which loop statements does Java support? Give...Ch. 4 - How many iterations do the following loops carry...Ch. 4 - Write pseudocode for a program that prints a...Ch. 4 - Prob. 15RECh. 4 - Write pseudocode for a program that reads a...Ch. 4 - Write pseudocode for a program that reads a...Ch. 4 - Rewrite the following for loop into a while loop....Ch. 4 - Rewrite the following do loop into a while loop....Ch. 4 - Provide trace tables of the following loops. a....Ch. 4 - What do the following loops print? Work out the...Ch. 4 - What do the following program segments print? Find...Ch. 4 - Prob. 23RECh. 4 - Add a storyboard panel for the conversion program...Ch. 4 - In Section 4.6, we decided to show users a list of...Ch. 4 - Change the storyboards in Section 4.6 to support a...Ch. 4 - Draw a flowchart for a program that carries out...Ch. 4 - In Section 4.7.5, the code for finding the largest...Ch. 4 - What are nested loops? Give an example where a...Ch. 4 - The nested loops for (int 1 = 1; 1 = height; i++)...Ch. 4 - Suppose you design an educational game to teach...Ch. 4 - In a travel simulation, Harry will visit one of...Ch. 4 - Write programs with loops that compute a. The sum...Ch. 4 - Write programs that read a sequence of integer...Ch. 4 - Write programs that read a line of input as a...Ch. 4 - Complete the program in How To 4.1 on page 171....Ch. 4 - Write a program that reads a set of floating-point...Ch. 4 - Translate the following pseudocode for finding the...Ch. 4 - Translate the following pseudocode for randomly...Ch. 4 - Write a program that reads a word and prints each...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints all...Ch. 4 - Write a program that reads a string and prints the...Ch. 4 - Write a program that reads a sequence of words and...Ch. 4 - Write a program that prints all powers of 2 from...Ch. 4 - Write a program that reads a number and prints all...Ch. 4 - Prob. 18PECh. 4 - Write a program that reads an integer and...Ch. 4 - Write a program that reads an integer and...Ch. 4 - Write a program to plot the following face.Ch. 4 - Write a graphical application that displays a...Ch. 4 - Enhance Worked Example 4.1 to check that the...Ch. 4 - Mean and standard deviation. Write a program that...Ch. 4 - The Fibonacci numbers are defined by the sequence...Ch. 4 - Factoring of integers. Write a program that asks...Ch. 4 - Prime numbers. Write a program that prompts the...Ch. 4 - The game of Nim. This is a well-known game with a...Ch. 4 - The Drunkards Walk. A drunkard in a grid of...Ch. 4 - The Monty Hall Paradox. Marilyn vos Savant...Ch. 4 - A simple random generator is obtained by the...Ch. 4 - The Buffon Needle Experiment. The following...Ch. 4 - In the 17th century, the discipline of probability...Ch. 4 - Write a program that reads an initial investment...Ch. 4 - Currency conversion. Write a program that first...Ch. 4 - Write a program that first asks the user to type...Ch. 4 - Your company has shares of stock it would like to...Ch. 4 - Write an application to pre-sell a limited number...Ch. 4 - You need to control the number of people who can...Ch. 4 - Credit Card Number Check. The last digit of a...Ch. 4 - In a predator-prey simulation, you compute the...Ch. 4 - Projectile flight. Suppose a cannonball is...Ch. 4 - Radioactive decay of radioactive materials can be...Ch. 4 - The photo at left shows an electric device called...Ch. 4 - Write a graphical application that draws a spiral,...Ch. 4 - Prob. 28PPCh. 4 - Draw a picture of the four-leaved rose whose...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify Program 7.8 so that the value of e is passed as an argument to the function. Try experimenting with diff...
Programming in C
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing the Digital Firm (15th Edition)
Explain why software testing should always be an incremental, staged activity. Are programmers the best people ...
Software Engineering (10th Edition)
Explain how database administration tasks vary with the size and complexity of the database.
Database Concepts (8th Edition)
What does the following code print? System.out.printf("%s%n%s%n%s%n", "", "", "");
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
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
- 5- What is the output for y? int y = 0; for (int i = 0; i< 10; ++i) { y +=i; } cout << y;arrow_forward#include <stdio.h>int main(){int i, j, k=0;for (i=1; i<3; i++){for (j=1; j<3; j++){k = i+j;printf("Value of k is %d\n" ,k);}}printf("Value of k is %d\n",2*k);return 0;} how do you modify this code so k only prints even numbersarrow_forwardLanguage: JAVA Leap-Year Write a program to find if a year is a leap year or not. We generally assume that if a year number is divisible by 4 it is a leap year. But it is not the only case. A year is a leap year if − It is evenly divisible by 100 If it is divisible by 100, then it should also be divisible by 400 Except this, all other years evenly divisible by 4 are leap years. So the leap year algorithm is, given the year number Y, Check if Y is divisible by 4 but not 100, DISPLAY "leap year" Check if Y is divisible by 400, DISPLAY "leap year" Otherwise, DISPLAY "not leap year" For this program you have to take the input, that is the year number from an input file input.txt that is provided to you. The input file contains multiple input year numbers. Use a while loop to input the year numbers from the input file one at a time and check if that year is a leap year or not. Create a class named LeapYear which will contain the main method and write all your code in the main…arrow_forward
- After the following code is executed, what is the value of i? int i;int *p;p = &i;i = 1;*p = 2;arrow_forwardQ1:Find the output of the following code:arrow_forwardint test(int *x, int y){ x=&y; return(*x+y); } int main(void) { int x=1, y=6; test(&y, x); printf("%d %d %d", x, test (&y,x),y); return 0; } 1 2 6arrow_forward
- #includecstdio.h> int x=10; void func1() 7 printf("x=%d\n", x); return; 8 10 int func2(int a, int b) 15 return a+b; 16 18 19 ... func3(...) 20 21 .. return ... int main() 27 { int x-1, y=2; func1(); 28 29 30 int z=func2(x, y); printf("z-%d\n", z); 31 34 Figure 2. C Program for Q2 What is the output after execution of line 29 and 32? a. b. func3() in line 19 to 23 is incomplete. Write the function, func30 to compute and print the volume of cuboid with length x, width y and height z. c. Complete line 33 to call func3() that you created in part (b).arrow_forward#include #include #include int main() { int i, j; printf("Columns | JIn"); for (i = 1; i< 4; ++i) { printf("Outer %6d\n", i); for (j = 0; j< i; ++j) { printf(" Inner%10d\n", j); } } /* heading of outer for loop */ /* heading of inner loop */ %3D return (0); } Create a new code modifying it to use "while loop" instead of the "for loop"arrow_forward#include main() {int=a, b=2, x=0, x=a + b * a + 10/2 * a, printf("value is =%d", x);} What is the value?arrow_forward
- 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?arrow_forwardbe recor #include #include minutes #include limit on int func(int, int, int, int); main(){ srand(time(NULL)); int a, b, c, fNum; printf("Choose three different numbers between 0-39:"); scanf ("%d%d%d", &a, &b, &c); fNum = func (a, b, c, 25); printf("\nThe result: %d", fNum); } int func (int ul, int u2, int u3, int iter){ srand (time (NULL)); int n1=0, i=0, count=0; for (;iarrow_forwardLucky Customer Code in C Languagearrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License