数据加载中……
乘法表打印 ----我的编写过程
 1/*
 2 * 失败案例 注意while循环结构
 3 * 哈哈^_^ 整数平方表 歪打正着
 4 * */

 5public class chengfa {
 6    public static void main (String[] args){
 7        int cheng,a=1,b=1;
 8        System.out.println("\n");
 9        while( a<=9){
10            /*
11             * 失败原因在while循环中迭代是同步的
12             * 所以总是a=b 九九乘法表没有打出来
13             * 倒是打出来1-10的整数的平方
14             */

15            while(b<=a){
16                cheng=a*b;
17                if(b<a){
18                    System.out.print(a+"*"+b+"="+cheng+"\t");
19                }
else{
20                    System.out.println(a+"*"+b+"="+cheng+"\t");
21                }

22                b++;
23            }

24            a++;
25        }

26    }

27}

28
29
30
又一个
 1public class chengfabiao 
 2    public static void main(String[] args)
 3        int i=1,j=1
 4        int result; 
 5        for(i=1;i<=9;i++
 6            for(j=1;j<=i;j++)
 7                result=i*j; 
 8                if(j<i) 
 9                    System.out.print(i+ "*" + j + " = " + result + "   "); 
10                }
 else 
11                    System.out.println(i+ "*" + j + " = " + result + "   "); 
12                }
 
13            }
 
14        }
 
15    }
 
16}
 1public class chengfabiao1 
 2    public static void main(String args[]) 
 3        int i,j,result; 
 4        for (i=1;i<=9;i++
 5            for (j=1;j<=i;j++
 6                result=i*j; 
 7                System.out.print(i + "*" + j + "=" + result + "\t"); 
 8            }
 
 9            System.out.print("\n"); 
10        }
 
11    }
 
12}

posted on 2008-08-21 18:40 月下峰 阅读(147) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: