你那个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;
}
}
}