Explanation of Solution
Given: The lines of Java code:
int n, m;
for (n = 1; n <= 10; n++)
for (m = 10; m >= 1; m--)
System.out.println(n + " times " + m+ " = " + n*m);
To find: The output of the lines of code in Java language and comment on the code:
int n, m;
for (n = 1; n <= 10; n++)
for (m = 10; m >= 1; m--)
System.out.println(n + " times " + m+ " = " + n*m);
Solution:
In this code:
Two variables, m and n, are declared.
In the outer for loop, the variable n will increment from 1 to 10 in ascending order and variable m in the inner for loop will decrement from 10 to 1.
In the outer loop, the value of n iterates from 1 and gets incremented by 1 if n<=10.
Then, it moves to the inner loop in which the value of m iterates from 10 and gets decremented by 1 till m>=1.
For every value of n, the inner loop repeats itself till the condition of m>=1 is satisfied and it executes the print statement for every value of m...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Absolute Java (6th Edition)
- ntegers outerRange and innerRange are read from input. Complete the outer while loop so the inner loop executes (outerRange + 1) * innerRange times. Ex: If the input is 6 5, then the output is: Inner loop ran 35 times import java.util.Scanner; public class LoopCounter { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int outerRange; int innerRange; int count; int i; int j; outerRange = scnr.nextInt(); innerRange = scnr.nextInt(); count = 0; i = 0; while (/* Your code goes here */) { j = 0; while (j < innerRange) { ++count; ++j; } ++i; } System.out.println("Inner loop ran " + count + " times"); } }arrow_forwardHow many times will the loop repeat? int j = 1; for(;<= 35; ) { } j++;arrow_forwardWrite a loop of your choice that continues to read an integer x as long as x not divisible by 5 and 3. Complete the missing code in the space provided below. { int x=1; ............ }arrow_forward
- The following loop displays ? for (int i = 1; i <= 10; i++) { if (i > 5) { break; } System.out.print(i + " "); i++;arrow_forwardtgn’sider the Given Loop: For(int i=0;iarrow_forwardThe following do...while loop rewritten as a for loop would be: int num = 5; do { System.out.print(num + " " ); num *= 3; //num = num * 3; } while (num <= 30); All of these are correct. int num = 5; for (num <= 30) { System.out.print(num + " "); num *= 3; } for (int num = 5; num <= 30) { System.out.print(num + " "); num *= 3; } for (int num = 5; num <= 30; num *= 3) { System.out.print(num + " " ); }arrow_forward
- the total number of iterations of nested loops can be calculated by : O a. outer loop iterations / inner loop iterations O b. outer loop iterations + inner loop iterations O c. outer loop iterations - inner loop iterations O d. outer loop iterations * inner loop iterationsarrow_forwardWrite a loop of your choice that continues to read an integer x as long as x is not in the range of [5,10]. Complete the missing code in the space provided below. int x=1; *** sarrow_forwardHow many times will the following for-loop execute? int i;for (i=1; i < 64; i = i*2) {...}arrow_forward
- Rewrite the following using a while-loop instead of a for-loop: int main(){ intk; int sum=0; for(k=10;k<50;k+=){ sum=sum+k; } cout<<"sum= " <<sum<<endl; system("pause"); return0;arrow_forwardWhich for statement repeats for all positive four-digit integers in decreasing order? I.e.: the for loop will repeat for 9999, 9998, 9997, ..., 1000. Select one: a. for (int j = 9999; j > 1000; j--) b. for (int j = 1000; j 999; j--) e. None of the othersarrow_forwardGiven x = 0, y = 1, count = 3. After the following code is executed, count ++; y=x; if (x < 0) count--; else count++; the value of y isarrow_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