Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.2, Problem 19STQ
What output is produced by the following code?
for (int n = 1; n <= 5; n||)
{
if (n –– 3)
System.exit(0);
System.out.println ("Hello");
}
System.out.println("After the loop");
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
int 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 6
#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).
3. What does this code print?
int i = 0;
while (i < 12)
{
int j;
for (j = 0; j < i; j++)
{
if ((i+j)%3
Ø)
==
j += 2;
}
i += j+1;
}
System.out.println("i = "+i);
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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 - Prob. 15PPCh. 4 - Prob. 16PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
(The Colorable interface) Design an interface named Colorable with a void method named howToColor (). Every cla...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
What will be displayed by the following program? my_value = 99 my_value = 0 print (my_value)
Starting Out with Python (3rd Edition)
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
Computers process data under the control of sets of instructions called
Java How To Program (Early Objects)
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
- How many line function error in the Code below? int fan = 3; int sensor-AD: int value=0,temp=0; float volt-0; LiquidCrystal Icd(8,9, 10, 11, 12, 13): void setup() { pinMode(fan,OUTPUT): Icd.begin(16, 2): Icd.print("Temp= "): Select one: a. 2 b. 1 C. 4 d. O e. 3arrow_forwardint i=0; while(i<10) { printf(“I am inside the loop”); } What is wrong with this block of C code? Mark the errors and fix them.arrow_forward#include void print(int n){ printf("Hello "); } if(n++ == 0) return; print(n); n++; int main(){ void print(); print(-4); } How many time printf execute?? And How ??arrow_forward
- 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_forward//Assignment 06 */public static void main[](String[] args) { String pass= "ICS 111"; System.out.printIn(valPassword(pass));} /* public static boolean valPassword(String password){ if(password.length() > 6) { if(checkPass(password) { return true; } else { return false; } }else System.out.print("Too small"); return false;} public static boolean checkPass (String password){ boolean hasNum=false; boolean hasCap = false; boolean hasLow = false; char c; for(int i = 0; i < password.length(); i++) { c = password.charAt(1); if(Character.isDigit(c)); { hasNum = true; } else if(Character.isUpperCase(c)) { hasCap = true; } else if(Character.isLowerCase(c)) { hasLow = true; } } return true; { return false; } }arrow_forward
- Consider the following code: public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); } What is printed by the call test_b(6)?arrow_forwardzain IQ docs.google.com Q The general form of (Compound if) is: If (condition); {statmenet1; } else {statmenet1; } * true False Int mark [5]= { 3, 77, 40, 1233}; * true O False 7. The output of this program is(49): int main ( ){int a=4,sum; while (a<=10) {sum+=a; a+=1;}cout << "The Total = << sum ;} * true Falsearrow_forwardEr main () int sum =0 ; for (int i31; i <=12; i++ if (i==4) break; sum = sum + i; cout<arrow_forwardSample for Multiple-ifarrow_forwardusing System; class Program { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { Console.WriteLine(number); number = number + 2; } Random r = new Random(); int randNo= r.Next(1,88); Console.WriteLine("Random Number between 1 and 88 is "+randNo); } } how can this program be fixed to select three random numbers between 1 and 88 instead of one?arrow_forward2- Trace the following code and write the output: class Test1 { Test1(int x) { System.out.println("Test Calls " + x); class Test2 { Testi t1 = new Test1(10); Test2(int i) { t1 = new Test1(i); } public static void main(String[] args) { Test2 t2 = new Test2(5);arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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