zhma 2022-06-16 15:19
浏览 21
已结题

123456231231

你那个java问题还需要吗?我已经写好了


package com.study.test;

/**
 * @author zhma
 * @version 1.0.0
 * @ClassName Test.java
 * @Description TODO
 * @createTime 2022年06月16日 14:35:00
 */
public class Test {


    public static void main(String[] args) {
        System.out.println("———————————————————————第4题——————————————————————————");
        jishu();
        System.out.println("----------------第五题-------------------");
        Circle circle = new Circle();
        circle.setCenter(1, 2);
        circle.setRadius(5);
        circle.getCenter();
        circle.getRadius();
        circle.getArea();
        System.out.println("----------------第六题-------------------");
        Car car = new Car();
        car.start();
        car.stop();
        Ship ship = new Ship();
        ship.start();
        ship.stop();
        System.out.println("----------------第七题-------------------");
        int[][] a = new int[][] { { 7, 5, 6 }, { 2, 3, 5 } };
        int[][] b = new int[][] { { 9, 5, 2, 8 }, { 5, 9 ,7 ,2 }, { 4, 7, 5, 8 } };
        int[][] c = multiplyMatrix(a, b);
        System.out.println("矩阵a");
        printMatrix(a);
        System.out.println("*");
        System.out.println("矩阵b");
        printMatrix(b);
        System.out.println("=矩阵c");
        printMatrix(c);

        System.out.println("----------------第八题-------------------");
        Poeple poeple = new Poeple();
        try {
            poeple.setAge(180);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    /*第四题*/
    public static void jishu() {
        for (int i = 0; i <= 74; i++) {
            System.out.println("当前计数:" + i);
            if (i == 74) {
                break;
            }
        }
    }
    /*-------------------------第五题-----------------------------*/

    static class Circle {

        private int centerX;

        private int centerY;

        private int radius;


        public String getCenter() {
            System.out.println("当前圆心坐标为:" + "(" + centerX + "," + centerY + ")");
            return "(" + centerX + "," + centerY + ")";
        }

        public void setCenter(int centerX, int centerY) {
            System.out.println("设置圆心坐标为:" + "(" + centerX + "," + centerY + ")");
            this.centerX = centerX;
            this.centerY = centerY;
        }


        public int getRadius() {
            System.out.println("获取圆半径:" + radius);
            return radius;
        }

        public void setRadius(int radius) {
            System.out.println("设置圆半径:" + radius);
            this.radius = radius;
        }

        public double getArea() {
            int r = this.radius;
            double area = Math.PI * r * r;
            System.out.println("当前圆面积:" + area);
            return area;
        }

    }


    /*-------------------------第六题-----------------------------*/
    interface Moveable {

        public void start();

        public void stop();

    }

    static class Car implements Moveable {

        @Override
        public void start() {
            System.out.println("汽车启动了");
        }

        @Override
        public void stop() {
            System.out.println("汽车停止了");
        }
    }

    static class Ship implements Moveable {

        @Override
        public void start() {
            System.out.println("轮船启动了");
        }

        @Override
        public void stop() {
            System.out.println("轮船停止了");
        }
    }

    /*-------------------------第七题-----------------------------*/

    public static int[][] multiplyMatrix(int[][] a, int[][] b) {
// 判断是否合法
        if (a == null || a == null || a.length == 0 || b.length == 0
                || a[0].length != b.length) {
            return null;
        }
// 计算相乘
        int[][] c = new int[a.length][b[0].length];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < b[0].length; j++) {
                for (int k = 0; k < a[0].length; k++) {
                    c[i][j] += a[i][k] * b[k][j];
                }
            }
        }
        return c;
    }

    // 打印矩阵
    public static void printMatrix(int[][] c) {
        if (c != null) {
            for (int i = 0; i < c.length; i++) {
                for (int j = 0; j < c[0].length; j++) {
                    System.out.print(c[i][j] + " ");
                }
                System.out.println();
            }
        } else {
            System.out.println("无效");
        }
        System.out.println();
    }


    /*-------------------------第八题-----------------------------*/
    static class Poeple {

        private int age;

        public int getAge() {
            return age;
        }

        public void setAge(int age) throws Exception {
            System.out.println("设置年轻:"+age);
            if (age < 1 || age > 130) {
                throw new Exception("年龄不能小于1,大于130");
            }
            this.age = age;
        }
    }

}




  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 6月24日
    • 创建了问题 6月16日

    悬赏问题

    • ¥200 基于同花顺supermind的量化策略脚本编辑
    • ¥20 Html备忘录页面制作
    • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?
    • ¥20 数学建模来解决我这个问题
    • ¥15 计算机网络ip分片偏移量计算头部是-20还是-40呀
    • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
    • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
    • ¥30 NIRfast软件使用指导
    • ¥20 matlab仿真问题,求功率谱密度
    • ¥15 求micropython modbus-RTU 从机的代码或库?