Java program to generate pattern:
Algorithm:
Code goes here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.util.*;</code></pre> class pattern { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int i,j,n; System.out.println("Enter the number of lines of pattern to be generated"); n=scan.nextInt(); //Taking the input from the user to generate the required pattern for(i=1;i<=n;i++) //Outer loop to count the lines { for(j=1;j<=i;j++)// Inner loop to generate the numbers in each line { System.out.print(" "+j); } System.out.println(" "); //Jump to next line in a pattern } } } |