zoukankan      html  css  js  c++  java
  • java用一个for循环输出99乘法表

     

    Java代码  收藏代码
    1. public static void main(String[] args) {  
    2.         for(int i=1,j=1;i<=9;){  
    3.                 System.out.print(j+"*"+i+"="+i*j);  
    4.                 if (j==i){  
    5.                     i++;  
    6.                     j=1;  
    7.                     System.out.println();  
    8.                 }else{  
    9.                     j++;  
    10.                     System.out.print(" ");  
    11.                 }  
    12.         }  
    13.     }  
    Java代码  收藏代码
      1. //以下是两个for实现  
      2. for(int i=1;i<=9;i++){  
      3.     for(int j=1;j<=i;j++){  
      4.         System.out.print(j+"*"+i+"="+i*j);  
      5.         if (j<i){  
      6.             System.out.print(" ");  
      7.         }  
      8.     }  
      9.     System.out.println();  
      10. }
      11. 优化
      12. public class nine{
            public static void main(String[] args) {  
                    for(int i=1,j=1;j<=9;i++){  
                            System.out.print(i+"*"+j+"="+i*j+" ");  
                            if (i==j){  
                                i=0;  
                                j++;  
                                System.out.println();  
                            }                   
                        }  
                    }  

            }

  • 相关阅读:
    POJ 3280 Cheapest Palindrome
    POJ 1191 棋盘分割
    POJ 1260 Pearls
    HDOJ 4731 Minimum palindrome
    2013 ACM/ICPC Asia Regional Chengdu Online 1004 Minimum palindrome
    POJ 1836 Alignment
    POJ 3267 The Cow Lexicon
    POJ 1276 Cash Machine
    POJ 1837 Balance
    HDU 4554 叛逆的小明
  • 原文地址:https://www.cnblogs.com/bb3q/p/4516685.html
Copyright © 2011-2022 走看看