中央論壇 - CENTER BBS

標題: IVE Lab 7-4 Sample [打印本頁]

作者: f66666602    時間: 2007-7-27 21:15
標題: IVE Lab 7-4 Sample
import javax.swing.*;

public class multi_table {
  
  static String input_string;
  static int input_int;
  static int cross, roll, num;
  static String space = "";
  static String result = "";
  
  public static void main(String[] args) {
   
    input_string = JOptionPane.showInputDialog(null, "Input a number of range", "The calculation of multiplication",
                                               JOptionPane.QUESTION_MESSAGE);
   
    input_int = Integer.parseInt(input_string);
   
    System.out.println("Multiplication Table\n");
    result = "";
    for (cross = 0; cross <= input_int; cross++) {
      num = cross;
      if (num < 10) {
        space = "  ";
      } else {
        space = " ";
      }
      if (num == 0) {
        result += "   ";
      } else {
        result += num + space;
      }
     
    }
    System.out.print(result + "\n");
   
    for (cross = 1; cross <= input_int; cross++) {
      result = "";
      for(roll = 1; roll <= input_int; roll++) {
        num = cross * roll;
        if (num < 10) {
          space = "  ";
        } else {
          space = " ";
        }
        result += space + num;
      }
      result += "\n";
      System.out.print(cross + result);
    }
  }
}




歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/) Powered by Discuz! X3