我有一个基于用户输入的循环增量值任务。基于用户输入循环显示增量值
的任务是,下面的线在控制台
*
**
***
****
*****
和线的量是由用户输入产生的决定。即如果用户在2它提供了以下的输出:
*
**
我当前的代码是:
import static javax.swing.JOptionPane.*;
public class loop1 {
public static void main(String[] args){
int current_line = 0;
String input_line = showInputDialog("type here ");
int target_line = Integer.parseInt(input_line);
while (current_line != target_line){
String sign = "*";
System.out.println(sign);
current_line ++;
}
}
}
但我似乎无法得到星号的数量(*),以增加每它运行的时间。我怎样才能做到这一点?
(它会更容易下手为'(;;)'循环在这个问题)。 – user2864740 2014-09-29 18:29:31
我真的建议在看这个http://mathbits.com/MathBits/Java/Looping/NestedFor .htm这是我会用的。 – StephenButtolph 2014-09-29 18:30:16