What do the following program segments print? Find the answers by tracing the code, not by using the computer.
- a. int n = 1;
for (int i = 2; i < 5; i++) { n = n + i; }
System.out.print(n);
- b. int i;
double n = 1 / 2;
for (i = 2; i <= 5; i++) { n = n + 1.0 / i; }
System.out.print(i);
- c. double x = 1;
double y = 1;
int i = 0;
do
{
y = y /2;
x = x + y;
i++;
}
while (x < 1.8);
System.out.print(i);
- d. double x = 1;
double y = 1;
int i = 0;
while (y >= 1.5)
{
x = x / 2;
y = x + y;
i++;
}
System.out.print(i);
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out With Visual Basic (8th Edition)
Artificial Intelligence: A Modern Approach
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out With Visual Basic (7th Edition)
- What is the probability that in a classroom of x people, at least 2 will be born on the same day of the year (ignore leap year)? Use a Monte Carlo Simulation and a frequency table to write a program that calculates this probability, where the number of people (x) in the simulated class is given by the user. The probability for a class of size 23, should be right around 50%. I have an outline for the code but please only use python language and NO "break", "true" language import mathimport random # create and initialize frequency table:ft = []k = 0while(k < 365) : ft.append(0) k = k+1 # Allow the user to determine class size:print("Please type in how many people are in the class: ")x= int(input()) success = 0 # Simulate:c = 0while(c < 10000) : # Step 1: re-initialize the birthday frequency table (it must be re-initialized for each play-through (why?): k = 0 while(k < 365) : ft[k] = 0 k = k+1 # Step 2: randomly get x birthdays and update frequency table: k =…arrow_forwardWrite a program which reads two integers and prints out the sum, the differenceand the product. Divide them too, printing your answer to two decimal places.Also print the remainder after the two numbers are divided. Introduce a test to ensure that when dividing the numbers, the second number isnot zeroarrow_forwardWrite this using java Write a complete version of the Bresenham Midpoint algorithm to handle ALL slope values. m = 0 m > 0 m < 0 m = 1 m > 1 swap the rolls of x and y m < 1 m = infinity ( needs special test case) Include appropriate tests for ‘special case’ conditions. Insteadof “WritePixel” write to the screen the coordinates of the pixel that would be drawn. Please provide photos that it works and so I can understand the code betterarrow_forward
- Write a program to read A[n, n] of numbers, then put 10 instead each evenpositive number.arrow_forwardWrite a program that produces a multiplication table, showing the results of multiplying the integers 1 through 12 by themselves.arrow_forwardWrite a program that reads a non-negative number n from the standard input and prints the value of the square root of n to the standard output, rounded down to the nearest integer. Write the program without using functions from the math libraryarrow_forward
- Write a program that generates 50 random numbers such that the first number is between 1 and 2, the second is between 1 and 3, the third is between 1 and 4, . . . , and the last is between 1 and 51.arrow_forwardWrite a short C++ or Python program to support your answer (for example, show that you checked whether there is no smaller number than your f by trying 128+f/2 == 128.arrow_forwardWrite a JAVA program for loop that will print out all the multiples of 3 from 3 to 36, that is: 3 6 9 12 15 18 21 24 27 30 33 36.arrow_forward
- Write this using java Write a complete version of the Bresenham Midpoint algorithm to handle ALL slope values. m = 0 m > 0 m < 0 m = 1 m > 1 swap the rolls of x and y m < 1 m = infinity ( needs special test case) Include appropriate tests for ‘special case’ conditions. Insteadof “WritePixel” write to the screen the coordinates of the pixel that would be drawn.arrow_forwardWrite a program that reads 10 numbers, finds the largest number, prints it, finds the smallest number, and prints itarrow_forwardWrite a program using Java to input a number of asterisks to print and a number to put on each line, then print out the asterisks as requested. Go to the next line after all asterisks have been printed. Sample Run: How many Asterisks :49 How many per line: 7 *************************************************arrow_forward
- 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