Q:

Java Program to print a pattern like a pyramid

0

Program to print a pattern like a pyramid by getting user input using for loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1 
{
  public static void main(String[] args)
        {
            int i,j,n,s,k;
            System.out.print ("Input number of rows : ");
            Scanner input = new Scanner(System.in);
            n = input.nextInt();

            s=n+4-1;
            for(i=1;i<=n;i++)
                 {
                  for(k=s;k!=0;k--)
                       {
                         System.out.print(" ");
                       }
                  for(j=1;j<=i;j++)
                       {
                         System.out.print(i+" ");
                       }
	    System.out.println();
            s--;
                 }
        }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now