【发布时间】:2017-03-01 17:29:53
【问题描述】:
我需要使用 for 循环、if-else 语句和 while 循环构造一个 10x15 乘法。它应该是这样的:
我的代码:
import java.util.Scanner;
public class Question2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
final int IMAX = 15;
final int JMAX = 10;
System.out.print(" |");
for(int j = 1; j<=JMAX; j++) {
System.out.print(" " + j);
// This printed the top header
}
System.out.println();
System.out.println("____________________________________________________________________________");
for(int i = 1; i<=IMAX; i++) {
System.out.print(" " + i + " |");
for (int j = 1; j <=JMAX; j++) {
if(j <= i)
System.out.print( i*j + " ");
else
System.out.println();
}
}
}
}
}
它正在输出:
我已经很接近搞清楚了,但我已经卡了 3 天了,我还没有使用过 while 循环。非常感谢任何帮助。
【问题讨论】:
-
因此,您需要将其中一个 for 循环转换为 while 循环。尝试搜索“convert for to while loop”
标签: java for-loop while-loop nested-loops