Answer:
class Main {
static void printPowers(int howMany, int nrRows) {
for(int n=1; n<=nrRows; n++) {
for(int power = 1; power<=howMany; power++) {
System.out.printf("%d ", (int) Math.pow(n, power));
}
System.out.println();
}
}
public static void main(String[] args) {
printPowers(3, 5);
}
}
class Main {
static void printPowers(int howMany, int nrRows) {
int n = 1;
do {
int power = 1;
do {
System.out.printf("%d ", (int) Math.pow(n, power));
power++;
} while (power <= howMany);
System.out.println();
n++;
} while (n <= nrRows);
}
public static void main(String[] args) {
printPowers(3, 5);
}
}
Explanation:
The for loop gives the cleanest, shortest code.