Question

What is the output of the following nested loops:    int m, n;    for (m...

What is the output of the following nested loops:

   int m, n;
   for (m = 3; m > 0; m--)
   {
       System.out.print((m – 3) + "\t");
       for (n = 0; n < 3; n++)
           System.out.print(m * n);
       System.out.println();
   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

output:

Loop 1
(m-3) prints 0 after that one tab space
0   n loop print m*n from n=0 to n
036
Loop 2
(m-3) prints -1 after that one tab space
-1   n loop print m*n from n=0 to n
024
Loop 3
(m-3) prints -2 after that one tab space
-2   n loop print m*n from n=0 to n
012


Add a comment
Know the answer?
Add Answer to:
What is the output of the following nested loops:    int m, n;    for (m...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 8 What is the exact output of the following nested loop? for (int row =...

    QUESTION 8 What is the exact output of the following nested loop? for (int row = 2; row<10; row += 4){ int column=1; while (column <= 4){ System.out.print(row - column + ""); column += 2; System.out.println(); wo- 1-153 1-1 53 All of these are correct.

  • What will be the output produced from the following nested loops: sum = 0; a =...

    What will be the output produced from the following nested loops: sum = 0; a = 7; while (a<10) {       for (k = a; k<=10; k++)                   sum +=k;       a++; } cout<< sum << endl; int x, y; for (x = 1; x<=5; x++) {       cout<<x<<endl;       for (y = 2; y <x; y++)                   cout<< y<<endl; }

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • C++ Write code using 2 nested loops, that produces the following output. Write code using 2...

    C++ Write code using 2 nested loops, that produces the following output. Write code using 2 nested loops, that produces the following output. 1 5 4 3 2 1 4 3 2 1 3 2 1 code.cpp New #include <iostream> 2 using namespace std; 3 4 int main() { 5 6 // TODO: your code go 7 8 9 2 1 1 }

  • pic 4: Loops What is the output of the following code? int main0 ( int x...

    pic 4: Loops What is the output of the following code? int main0 ( int x = 1; while (x < 7) t İf ( (x % 2)-= 1)(1/ if x is odd x=x+1; else t x = x + 2; return 0; Select óne O a. 124 6 8 O b. 1 234 5 6 7 O c. 246 O d. 24 6 8 PREVIOUS PAGE NE

  • what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int...

    what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int w 0; int x; int y 5; float z = 6.1 System.out.print("Enter y: "); x keyboard.nextint); System.out.println('y'); System.out.println(x); System.out.println(w*3); x- x+(int)z; System.out.println(x); 0 System.out.println(u); System.out.,println(u); System.out.println"x In" + y); System.out.print(y + z); ) liclosing main method 1 liclosing class header

  • Help with a question in Java: What is the output from the following program? public class...

    Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }

  • (a)How many times does the code snippet given below display "Hello"? int x = 1; while...

    (a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) {    System.out.println ("Hello");    x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) {    sum = sum + i;    i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...

  • What is the complexity of the following nested loops? for i = n to 1 step...

    What is the complexity of the following nested loops? for i = n to 1 step -1 do     j ← i     while j ≥ 1                                    Θ(j) statement                                  j ←   ëj/2û                             endwhile                         endfor

  • in JAVA write a program that produces the following output using nested for loops: +------+ |...

    in JAVA write a program that produces the following output using nested for loops: +------+ | ^^ | | ^ ^ | |^ ^| | ^^ | | ^ ^ | |^ ^| +------+ | vv | | v v | |v v| | vv | | v v | |v v| +------+

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT