Question

For JAVA Please post code in bold. Thank you.

Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints:

0
 1
  2
   3

Challenge 4.6.1: Nested loops ndent text. Activity

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

public class NestedLoop
{
   public static void main (String [] args)
   {
       int userNum = 3;
       int i = 0;
       int j = 0;

       for (i = 0; i <= userNum; i++)
       {
           for (j = 0; j < i; j++)
           {
               System.out.print(" ");
           }
          
           System.out.println(i);
       } return;
   }
}

Ek Problems @ Javadoc R. Declaration g console × <terminated NestedLoop [Java Application] C:\Program Filesavare7\bin\javaw.e

Know the answer?
Add Answer to:
For JAVA Please post code in bold. Thank you. Print numbers 0, 1, 2, ..., userNum...
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
  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

    Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3

  • HALLENGE 4.6.1: Nested loops: Indent text ACTINITY Print numbers 0, 1,2, userNum as shown, with each...

    HALLENGE 4.6.1: Nested loops: Indent text ACTINITY Print numbers 0, 1,2, userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newine. Hint Use i and jas loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Exc userNum 3 prints 0 2

  • AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as...

    AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex userNum-3 prints 3 int noin(void){ 6 int 1- Your solution goes here 1e return...

  • Print numbers 0,1,2,userNum as shown, with each number indented by that number of spaces

    Print numbers 0,1,2,userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex user Num = 3 prints: 

  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

    Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Sample program: #include <stdio.h> int main(void) { int userNum = 0; int i =...

  • Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print...

    Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print numbers 0, 1,2userNum as shown, with each number indented by that number of spaces For each printed line, print the leading spaces, then the number, and then a newline Hint. Use i and j as loop variables (initialize i and j explicitly). Note. Avoid any other spaces like spaces after the printed number Ex userNum-3 prints

  • Not sure how to get rid of the spaces at the end. Thanks for any help...

    Not sure how to get rid of the spaces at the end. Thanks for any help learn.zybooks.com 21.7. Nested loops zyBooks My library EGR 219 home 21.7: Nested loops E zyBooks catalog Help/FAQ Dennis Roberts CAHALE.7.1: Nested loops: Indent text Print numbers 0, 1,2,. serNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize...

  • Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...

    Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an...

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
ADVERTISEMENT