Professional Documents
Culture Documents
Pyramid Printing
Pyramid Printing
Pyramid Printing
*;
class PyramidPrinting {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// System.out.println("Stars:" + getStars(1));
// System.out.println("Stars:" + getStars(2));
}
// eg: i=1,
// *
// eg: i = 2,
// * *
public static String getStars(int i) {
StringBuilder starBuilder = new StringBuilder();
if (i == 0) {
System.out.println("This is probably passed by error");
}
// System.out.println(starBuilder.toString().length());
return starBuilder.toString();
}
// for i : 1 to 4
for (int i = 0; i < n ; i++) {
// eg: i=1,
// *
// eg: i = 2,
// * *
pyramidStars[i] = getStars(i + 1);
} // for i.
// for each i, getStars(i)
// the return string gets appended to the array
// return the string array
// TODO: Make sure that there are no trailing space after the last star
return pyramidStars;
}
}
// 1
// *
// Make sure that there are no trailing space after the last star
// - Try to offload processing to functions & keeping your main code small.
// Milestone 4: Prove to the interviewer that your code works with unit tests
// - Make sure you check boundary conditions