总结两轮之间的值,这是我的任务。使用FOR循环,并在Java中
“写程序LoopForNumberSum.java只显示每秒数,从2日开始,到屏幕上和在括号上轮之间到目前为止,循环范围由单独的变量定义,使用FOR-loop解决问题。“
这是代码我迄今为止:
public class LoopForNumberSum {
public static void main(String args[]) {
int min = 2;
int max = 10;
for(int i = min; i <= max; i+=2) {
int j = i+i;
System.out.println(i + "(" + j + "), ");
}
}
}
^这个代码打印:
2(4),
4(8),
6(12 ),
8(16),
10(20),
但我需要在括号中的数字从2开始,其余需要是6,10,14和18.像这样:“2(2),4(6) ......”
提示:您需要在循环外部声明的变量到目前为止存储 – antlersoft 2014-09-04 19:36:31
哦,是的,当然值! – user1589375 2014-09-04 19:45:28