java--函数

打印三角形:

public class FunctionDemo01 {
    
    public static void main(String[] args) {
        
        getResult(4);
    }

    public static void getResult(int row){
        
        for (int x = 0; x < row; x++) {
                
            for (int y = 0; y < x+1; y++) {
                System.out.print("*");
            }
            System.out.println();
        }        
    }
}

打印矩形:

public class FunctionDemo01 {
    
    public static void main(String[] args) {
        
        getResult(4,5);
    }

    public static void getResult(int row,int col){
        
        for (int x = 0; x < row; x++) {
                
            for (int y = 0; y < col; y++) {
                System.out.print("*");
            }
            System.out.println();
        }        
    }
}

九九乘法表:

public class FunctionDemo01 {
    
    public static void main(String[] args) {
        
        getResult(9);
    }

    public static void getResult(int row){
        
        for (int x = 1; x <= row; x++) {
                //1*1=1
                //1*2=2 2*2=4
                //1*3=3 2*3=6 3*3=9
            for (int y = 1; y <= x; y++) {
                System.out.print(y+"*"+x+"="+x*y+"\t");

            }
            System.out.println();
        }        
    }
}

 

posted @ 2017-11-27 11:00  大漠之烟  阅读(173)  评论(0编辑  收藏  举报