平时作业(偷懒)
平时作业
一.
package zuoye;
public class zuoye01 {
public static int Random(int n) {
return (int)(n * Math.random());
}
public static void main(String[] args) {
int n = 100; // 假设n为100,可以根据需求修改
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;
}
if (num >= 60) {
count++;
}
}
System.out.println("最大值: " + max);
System.out.println("最小值: " + min);
System.out.println("大于等于60的个数: " + 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());
}
}
打卡!打卡!打卡!打卡!打卡!

