정보과학 IT

두가지 구구단으로 익히는 Java

물곰탱이 2013. 10. 9. 15:33

public class 사열구구단클래스 {

   public static void main(String[] args) {

      System.out.format("%n                   < SKY 구구단 >%n");


//      for (int j = 1; j <= 9; j++) {
   for (int i = 2; i <= 5; i++) {  // 2단 ~ 5단까지
//       for (int i = 1; i <= 5; i++) {
        System.out.println();
        for (int j = 1; j <= 9; j++) {  // 2단 ~ 5단까지
//        for (int i = 2; i <= 5; i=i+1) {  // 2단 ~ 5단까지
//          System.out.format("%d X %d = %2d   ", i, j, i * j);
             System.out.println(i + " X " + j + " = " + i * j);
//             System.out.println(j + " X " + i + " = " + i * j);

        }
      }


      System.out.println(); // 줄바꿈
      System.out.format("--- sky --- SKY --- 구구단 ---"); //


      for (int j = 1; j <= 9; j++) {
        System.out.println();
        for (int i = 6; i <= 9; i++) {  // 6단 ~ 9단까지
          System.out.format("%d X %d = %2d   ", i, j, i * j);
        }
      }


      System.out.println(); // 줄바꿈


    }
  }

 

public class 일렬구구단클래스 {

//   public static void main(String[] args) {
//   static public void main(String[] args) {
   static public void main(String args[]) {
 
 int temp  = 0;

    for (int j = 2; j < 10; j++) {

        System.out.println(j + " 단 ");

        for (int i = 1; i < 10; i++) {

            temp = j * i;

//            System.out.println(j + " X " + i + " = " + i * j);
            System.out.format("%d X %d = %2d   %n", j , i , temp);
//            System.out.format("%d X %d = %2d   ", j , i , temp);

        }

  }

  System.out.println("temp=" + temp);

}
}