java - Display stars based on array values using showOptionDialog -
what best way display each value in array n times star in case (using showoptiondialog)? considering using loop, i'm not sure i'd fit in code.
code far:
int[] stars = {2,4,6}; string[] options = {"yes","no"} int choice = joptionpane.showoptiondialog(null, "stars1: " + stars[0]... + "\n stars2:" + stars[1]... + "\n stars3:" + stars[2]..., "stars", 0, 3, null, options, null);
expected output:
** **** ******
hope makes sense, thanks!
you can try this:
int[] stars = {2,4,6}; string[] starsstr = new string[stars.length]; for(int = 0;i < stars.length;i++){ string temp = ""; for(int j = 0; j < stars[i];j++){ temp+="*"; } starsstr[i] = temp; } string[] options = {"yes","no"}; int choice = joptionpane.showoptiondialog(null, starsstr, "stars", 0, 3, null, options, null);
Comments
Post a Comment