File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
InterviewPrograms/src/com/java/patterns Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .java .patterns ;
2+
3+ import java .util .Scanner ;
4+
5+ /*
6+ Write a Java Program to print the following Pattern
7+ 1 1 1 1 1
8+ 2 2 2 2 2
9+ 3 3 3 3 3
10+ 4 4 4 4 4
11+ 5 5 5 5 5
12+ */
13+ public class Pattern11 {
14+ public static void main (String [] args ) {
15+ Scanner scanner = new Scanner (System .in );
16+ System .out .println ("Enter the number of rows to print the pattern :: " );
17+ int N = Integer .parseInt (scanner .nextLine ().trim ());
18+ for (int i =0 ;i <N ;i ++){
19+ for (int j =0 ;j <5 ;j ++)
20+ if (j == 4 )
21+ System .out .print ((i +1 )+"" );
22+ else
23+ System .out .print (i +1 +" " );
24+ if (i < N -1 )
25+ System .out .println ("" );
26+ }
27+ scanner .close ();
28+ }
29+ }
30+ /*
31+ OUTPUT
32+ Enter the number of rows to print the pattern :: 5
33+ 1 1 1 1 1
34+ 2 2 2 2 2
35+ 3 3 3 3 3
36+ 4 4 4 4 4
37+ 5 5 5 5 5
38+
39+ Enter the number of rows to print the pattern :: 2
40+ 1 1 1 1 1
41+ 2 2 2 2 2
42+ */
You can’t perform that action at this time.
0 commit comments