117k views
4 votes
Class Main {

public static void main(String[] args) {


int n=1;


while(n<=5) {


int power = 1;


while(power <= 3) {


System.out.printf("%d ", (int) Math.pow(n,power));


power++;


}


System.out.println();


n++;


}


}


}

Class Main { public static void main(String[] args) { int n=1; while(n<=5) { int-example-1

1 Answer

12 votes

Answer:

class Main {

static void printPowers(int howMany, int nrRows) {

int n=1;

while(n<=nrRows) {

int power = 1;

while(power <= howMany) {

System.out.printf("%d ", (int) Math.pow(n,power));

power++;

}

System.out.println();

n++;

}

}

public static void main(String[] args) {

printPowers(3,5);

}

}

Step-by-step explanation:

Created a method with two parameters.

User Martin Redmond
by
4.1k points