Skip to content

Commit

Permalink
Merge pull request #57 from Sahilkumar19/master
Browse files Browse the repository at this point in the history
Feature : Printing patterns Using a Single Loop
  • Loading branch information
HarryDulaney authored Aug 26, 2023
2 parents 13b2c4f + afd1083 commit 450a931
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions ch_01/Exercise01_04.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,10 @@
public class Exercise01_04 {

public static void main(String[] args) {
int a = 2;
int b = 3;
int c = 4;

for (int i = 0; i < 5; i++) {
if (i > 0) {
System.out.print("\n");
}
for (int j = 0; j < 3; j++) {

if (i == 0) {
if (j == 0)
System.out.print("a ");
if (j == 1)
System.out.print("a^2 ");
if (j == 2)
System.out.print("a^3");

} else if (i == 1) {
System.out.print("1 ");
} else if (i == 2) {
System.out.print(a + " ");
a *= 2;

} else if (i == 3) {
System.out.print(b + " ");
b *= 3;

} else {
System.out.print(c + " ");
c *= 4;

}


}


int num = 4;
for (int row = 1; row <= num; row++) {
System.out.println(row + " " + row * row + " " + row * row * row);
}

}


}

0 comments on commit 450a931

Please sign in to comment.