当前位置: 首页 > article >正文

平时作业

java作业

package zuoye;
​
public class zuoye02 {
    public static int Random(int n) {
        return (int)(n * Math.random());
    }
    public static void main(String[] args) {
        int n = 100;
        //System.out.println(Random(n));
        int[]random = new int[50];
        for(int i = 0; i <50; i++) {
            random[i] = Random(n);
        }
        int max = random[0];
        int min = random[0];
        int count = 0;
        for(int num : random) {
            if(num > max) {
                max = num;
            }
            if(num < min) {
                min = num;
            }
            count++;
        }
        System.out.println("最大值为"+max);
        System.out.println("最小值为"+min);
        System.out.println("个数为"+count);
    }
}
package zuoye;
class Vehicle1{
    private int speed;
    private int size;
​
    public void move() {
​
    }
    public void setSpeed(int speed) {
        this.speed = speed;//看不懂
    }
    public void speedUp() {
        speed++;
    }
    public void speedDown() {
        if(speed>=0) {
            speed--;
        }
    }
    public int getSpeed() {
        return speed;
    }
    public int getSize() {
        return size;
    }
    public void setSize(int size) {
        this.size = size;
    }
}
​
public class Vehicle {
    public static void main(String[] args) {
        Vehicle1 v1 = new Vehicle1();
        v1.setSpeed(10);
        v1.setSize(10);
        System.out.println("初始速度"+v1.getSpeed());
        System.out.println("初始体积"+v1.getSize());
        v1.speedUp();
        System.out.println("加速后速度"+v1.getSpeed());
        v1.speedDown();
        System.out.println("减速后速度"+v1.getSpeed());
    }
}

打卡!打卡!打卡!打卡!打卡!


http://www.kler.cn/a/584021.html

相关文章:

  • C语言一维数组
  • 使用 ESP32 和 Python 进行手势识别
  • 【redis】list类型:基本命令(下)
  • C++复试笔记(三)
  • uniapp 实现的步进指示器组件
  • C++设计模式-原型模式:从基本介绍,内部原理、应用场景、使用方法,常见问题和解决方案进行深度解析
  • OpenHarmony 编译运行qemu模拟设备
  • MyBatis 中SQL 映射文件是如何与 Mapper 接口关联起来的? MyBatis 如何知道应该调用哪个 SQL 语句?
  • Tomcat新手入门指南:从零开始搭建Web服务器
  • SSR 框架是什么?
  • 使用 OpenAI 的 Node.js 通过 Ollama 在本地运行 DeepSeek R1
  • 工厂变电所运维云平台解决方案-直击运维痛点,重塑高效安全运维典范
  • 框架源码私享笔记(02)Mybatis核心框架原理 | 一条SQL透析核心组件功能特性
  • 过滤器(Filter)与拦截器(Interceptor)
  • 【Git】所有文章传送门(持续更新...)
  • eNSP中路由器的CON/AUX接口、GE Combo接口、Mini USB接口、USB接口、WAN侧uplink接口、FE接口、GE接口介绍
  • C++程序员职业规划
  • IP层之分片包的整合处理---BUG修复
  • celery入门
  • 大模型架构记录5-向量数据库