• 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+"	");
    
                }
                System.out.println();
            }        
        }
    }

  • 相关阅读:
    chm文件生成
    java基础--集合
    java基础--多线程
    nexus
    java基础--IO流
    http与https
    java基础--数据结构
    mysql 优化
    maven依赖和传递
    java设计模式
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/7903149.html
Copyright © 2020-2023  润新知