File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package Pattern_Printing ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Odd_Number_Triangle {
6+ public static void main (String [] args ) {
7+ Scanner sc = new Scanner (System .in );
8+ System .out .println ("Enter a number" );
9+
10+ int n = sc .nextInt ();
11+ for (int i =1 ;i <=n ;i ++) {
12+ int a =1 ;
13+
14+ for (int j =1 ;j <=i ;j ++) {
15+ // System.out.print(a++ +" ");
16+ // a=a+1;
17+ System .out .print (2 *j -1 +" " );
18+ }
19+ System .out .println ();
20+ }
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -11,13 +11,14 @@ public static void main(String[] args) {
1111 int n = sc .nextInt ();
1212
1313 for (int i =1 ;i <=n ; i ++) {
14- for (int j =1 ; j <=i ; j ++) {
14+ // for(int j=1; j<=i; j++) {
15+ for (int j =1 ;j <=i ;j ++) {
1516
1617 System .out .print ("* " );
1718
1819
1920 }
20- System .out .println ();
21+ System .out .println ();
2122 }
2223}
2324}
Original file line number Diff line number Diff line change 1+ package Pattern_Printing ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Triangle_Flipped_Vertical {
6+ public static void main (String [] args ) {
7+
8+ Scanner sc = new Scanner (System .in );
9+
10+ System .out .println ("Enter a number " );
11+ int n = sc .nextInt ();
12+
13+ for (int i =1 ;i <=n ; i ++) {
14+ // for(int j=1; j<=i; j++) {
15+ for (int j =1 ;j <=n -i ;j ++) {
16+
17+ System .out .print (" " );
18+
19+
20+ }
21+ for (int k =1 ;k <=i ;k ++) {
22+ System .out .print ("* " );
23+
24+ }
25+ System .out .println ();
26+ }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments