posts - 137,comments - 0,views - 40818
复制代码
public class test1 {
    public static void main(String[] args){
        printRectangle(3,5);  //调用printRectangle方法实现打印矩形
        printRectangle(2,4);  
        printRectangle(6,10);
    }
    public static void printRectangle(int height,int width){ 
        for (int i=0;i<height;i++){   //方法就是一段可以重复调用的代码
            for (int j=0;j<width;j++){
                System.out.print("*");
            }
            System.out.println();
        }
        System.out.println();
    }
}
复制代码

复制代码
public class test1 {
    public static void main(String[] args) {
        int area = getArea(3, 5);
        System.out.println("The area is " + area);
    }
    public static int getArea(int height,int width) {
        int area = height * width;
        return area;
    }
}
复制代码

 

posted on   wshidaboss  阅读(561)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示