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
Expert Solution & Answer
Chapter 4.1, Problem 7STQ
Explanation of Solution
Given code:
The below code is used to print the values from 1 to 4 using “for” loop.
//Define the Main class
public class Main
{
//Define main method
public static void main(String[] args)
{
//Loop from 1 to 4
for(int n=1; n<=4; n++)
&...
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
What is the final value of x when the following code is run?
int x;for(x =1; x<20; x+=2) {}
Read the code segment below. What will be the output of the code segment?
for (int i = 0; i <= 11; i++) { System.out.println(arr[i*2]);}314159265358979323846
34525599286with an error
31415926535
34525599286
5- What is the output for y?
int y = 0;
for (int i = 0; i< 10; ++i)
{
y +=i;
}
cout << y;
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
Knowledge Booster
Similar questions
- What is the value of x when i = 4? #include int main (void) { int x = for (int i = 0; i <= 4; ++i) { X = X + i; } printf("%d %d", i, x); return 0; }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_forwardwhat is the output of the following code? X = [12 3;4 5 6;7 8 9];Y = [9 8 7;6 5 4;3 * (2 1]; r= rem(X,Yarrow_forward
- What is the output of this code? def func(a,b): if(b==1): return a else: return a* func(a,b-1) A It adds a and b (B) None of these choices © It multiplies a and b (D) It raises a to the power of barrow_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_forwardWhat is printed in the piece of code below ?arrow_forward
- 31. What is the output of the folowing code? int count; int num 2; for (count - 1; count = 1); System.out.printin (); a. 3 b. 3 1 C. 3 1 -1 d. None of these 34. Which modifier is used to specify that a method cannot be used outside a class? a. public b. abstract c. static d. private public static char methodHeading (int n, double num) 35. Based on the method heading above, what is the return type of the value returmed? a. static int c. d. num b. chararrow_forwardWhat is output of A = [1 0 2]; b = [30 7]; c=a.*b ?arrow_forward#include <stdio.h> struct Single { int num; }; void printSingle(int f) { int binaryNum[33]; int i = 0; while(f>0) { binaryNum[i] = f % 2; f = f/2; i++; } for (int j=i-1; j>= 0; j--) { printf("%d",binaryNum[j]); } } int main() { struct Single single; single.num = 33; printf("Number: %d\n",single.num); printSingle(single.num); return 0; }arrow_forward
- int fun(int k){ return ( ); void main(){ int n; cin >> n; n = n * fun(n); <-- 1 Fill in the appropriate statement and expression in fun, so that when it is called in main, and after the execution of the statement marked 1, the value of n would always be n3.arrow_forwardPlease help me indicate outputarrow_forwardTrue/false: The following program has a race on the value of myid. void *printld(void *vargp) { int myid="((int *)vargp); printf("%d\n", myid); return NULL; } int main() { } pthread_t tid[2]; int i; for (i = 0; i < 2; i++) Pthread_create(&tid[i], NULL, printld, &i); Pthread_join(tid[0], NULL); Pthread_join(tid[1], NULL);arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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