java程序,比较初级,题目如下,请给我清楚的程序。谢谢帮助

如题所述

根据第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

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网