潭州Java中级班(day_07)

练习一:打印出直角三角形

package com.tz.Test;

public class Test {
    public static void main(String[] args) {
        /*
         * 直角三角形
         */
        
        for(int i=1;i<=9;i++){  //控制行数
            for(int j=0;j<i;j++){
                System.out.print("*");
            }
            System.out.println();
        }
        
    }
    
}

 练习二:打印出等腰三角形

package com.tz.Test;

public class Test2 {
    public static void main(String[] args) {
        /*
         * 等腰三角形
         */
        for(int i=1;i<=10;i++){  //控制行数
            for(int j=10-i;j>=0;j--){  //显示空格
                System.out.print("1");
            }
            for(int y=1;y<=2*i-1;y++){  //打印
                System.out.print("*");
            }
            System.out.println();
        }
        
    }
    
}

 

 练习三:给数组排序

package com.tz.Test;

public class Test3 {
    public static void main(String[] args) {
        int s[]={20,32,10,12,14,16,8,7};  //定义了一个整形数组
        int a[]={25,36,98,45,12,0};  //定义了一个整形数组
        //sort(s);
        java.util.Arrays.sort(s);
        print(s);
        System.out.println("\n==============");
        java.util.Arrays.sort(a);
        print(a);
    }
    
//    public static void sort(int temp[]){  //排序
//        for(int i=1;i<temp.length;i++){
//            for(int j=0;j<temp.length;j++){
//                if(temp[i]<temp[j]){
//                    int x=temp[i];
//                    temp[i]=temp[j];
//                    temp[j]=x;
//                }
//            }
//        }
//    }
    
    
    /**
     * 
     * @param temp
     */
    public static void print(int temp[]){  //输出
        for(int i=0;i<temp.length;i++){
            System.out.print(temp[i]+"\t");
        }
    }
    
    /**
     * 我要实现两个数的定义
     * @param x 整数
     * @param y    整数
     * @return
     */
    
    public static int a(int x,int y){
        return 1;
    }
    
    
}

 练习四:打印99乘法表

package com.tz.Test;

public class Test4 {
    public static void main(String[] args) {
        /**
         * 99乘法表
         */
        for (int i = 1; i <= 9; i++) { // 控制行数
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "*" + i + "=" + (i * j) + "\t");
            }
            System.out.println();
        }
    }
}

 

posted on 2018-08-24 16:40  王育奕  阅读(135)  评论(0编辑  收藏  举报

导航