Visa Inc. interview question

How to write code that prints the following: * ** *** **** *****

Interview Answers

Anonymous

18 Feb 2016

int i, j, numStars = 6; for (i = 0; i < numStars; i++) { for (j = 0; j < i+1; j++) printf("*"); printf("\n"); }

2

Anonymous

22 Feb 2019

public class StarPrint { public static void main(String[] args) { int numbStar = 6; int row = 0; for (int i = 0; i < numbStar; i++) { for (int k = 0; k < row; k++) { System.out.print("*"); } row++; System.out.println(); } } }