Question
1. What values of i will the following loops iterate over? Give an explicit sequence for each for loop. If a loop is innite, just
1. What values of i will the following loops iterate over? Give an explicit sequence for each for loop. If a loop is innite, just give the rst few elements of the sequence and then use ... to mean that it continues on to innite (technically, Java integers would overow and wrap around to negative values, but ignore that for this question). (a) for (int i=2; i<=7; i++)
(b) for (int i=7; i>2; i--)
(c) for (int i=2; i<9; i+=3) (d) (1 point) for (int i=7; i>2; i+=2) (e) (1 point) for (int i=1; i<=20; i*=2) (f) (1 point) for (int i=7; i<=2; i--) 2. What is the output of the following code fragment? int prod = 1; for(int i=7; i > 4; i = i - 2) { prod = prod * i; } System.out.println(prod); 3. What does the following nested loop print out? for (int r=1; r <=5; ++r) { double x =10.0*r; for (int c=1; c<=5; ++c) { System.out.printf("%5.2f",c/x); } System.out.println(); } 4. What are the values in arrays a and b after the following code executes (list all of the elements of both arrays)? double[] a = new double[4]; double[] b = {6,4,2,0}; a[1] = b[0] + b[2]; a[a.length-1] = b[1]; b[0] = b[0]+a[1];
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started