Input: base=2, row = 3
Output:
**
****
********
Input: base=3, row = 3
Output:
***
*********
***************************
I have tried this way, but I spaces aren't printing properly.
import java.util.Scanner;
public class loops {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("enter base:");
int base = s.nextInt();
System.out.println("enter height:");
int h = s.nextInt();
for (int i = 1; i <= h; i++) {
int num = (int)Math.pow(base, i);
for(int n=h-1; n>i-1; n--) {
System.out.print(" ");
}
for (int j = 0; j < num; j++) {
System.out.print("*");
}
System.out.println("");
}
}
}