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
IN JAVA
import java.util.Scanner;
public class allTest {
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter number: ");
int n=in.nextInt();
for(int i=0;i<=n;i++)
{
for(int j=0;j<i;j++)
{
//for print
space
System.out.print(" ");
}
//for print number
System.out.println(i);
}
}
}
Get Answers For Free
Most questions answered within 1 hours.