如题所述
根据第7题的要求编写的Java程序如下:
import javax.swing.JOptionPane;public class TimesTable {
public static void printTimesTable(int n){
System.out.println("A times table with max multiplier:"+n);
//print column header
System.out.print("\t");
for(int j=0;j<=n;j++){
System.out.print(j+"\t");
}
System.out.println();
//print table
for(int i=0;i<=n;i++){
//print row header
System.out.print(i+"\t");
for(int j=0;j<=n;j++){
//print table cell
System.out.print(i*j+"\t");
}
System.out.println();
}
System.out.println("End of Processing");
}
public static void main(String[] args) {
String tablesize=JOptionPane.showInputDialog(null,"Please input table size:", 0);
int n=Integer.parseInt(tablesize);
printTimesTable(n);
}
}
运行结果:
A times table with max multiplier:7
0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 8 10 12 14
3 0 3 6 9 12 15 18 21
4 0 4 8 12 16 20 24 28
5 0 5 10 15 20 25 30 35
6 0 6 12 18 24 30 36 42
7 0 7 14 21 28 35 42 49
End of Processing
温馨提示:答案为网友推荐,仅供参考