java用一个for循环输出99乘法表

论坛 期权论坛 脚本     
匿名技术用户   2020-12-28 15:37   56   0
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("\t");
  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("\t");
    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+"\t");
      if (i==j){
      i=0;
      j++;
      System.out.println();
      }
      }
      }

      }

转载于:https://www.cnblogs.com/bb3q/p/4516685.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP