Java 使用showOptionDialog根据阵列值显示星星
在这种情况下(使用showOptionDialog),将数组中的每个值显示为n乘以一个星的最佳方式是什么? 我曾考虑使用for循环,但我不确定我在代码中的位置 迄今为止的代码:Java 使用showOptionDialog根据阵列值显示星星,java,joptionpane,Java,Joptionpane,在这种情况下(使用showOptionDialog),将数组中的每个值显示为n乘以一个星的最佳方式是什么? 我曾考虑使用for循环,但我不确定我在代码中的位置 迄今为止的代码: int[] stars = {2,4,6}; String[] options = {"yes","no"} int choice = JOptionPane.showOptionDialog(null, "stars1: " + stars[0]... + "\n stars
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);
预期产出:
**
****
******
希望这有意义,谢谢 您可以尝试以下方法:
int[] stars = {2,4,6};
String[] starsStr = new String[stars.length];
for(int i = 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);
int[]星={2,4,6};
String[]starsStr=新字符串[stars.length];
对于(int i=0;i
尝试编写一个方法,将整数转换为整数长度的字符串