第一章 矩形面积周长
public class Homewordk {
public static void main(String[] args) {
double area, perimeter;
Scanner scanner = new Scanner(System.in);
System.out.println("输入矩形的长宽");
double length = scanner.nextDouble();
double width = scanner.nextDouble();
area = length * width;
perimeter = 2 * (length + width);
System.out.println("面积是" + area);
System.out.println("周长是" + perimeter);
}
}
第二章
1年利率 math pow函数
public class Homewordk {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("依次输入投资总额 年利率 年数");
double totalInvestment = scanner.nextDouble();
double annualInterestRate = scanner.nextDouble();
int year = scanner.nextInt();
double monthInterestRate = annualInterestRate / 1200;
double futureInvestment = totalInvestment * Math.pow((1 + monthInterestRate), year * 12);
System.out.println(futureInvestment);
}
}
2一维数组 累加和
public class Homewordk {
public static double sum(double[] array) {
double sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}
public static void main(String[] args) {
System.out.println("输入6个double值");
Scanner scanner = new Scanner(System.in);
double[] array = new double[6];
for (int i = 0; i < array.length; i++) {
array[i] = scanner.nextByte();
}
System.out.println("累加和的值是" + sum(array));
}
}
3两个二维数组累加和
public class Homewordk {
public static double[][] setMartix(double[][] array) {
System.out.println("请输入数组的值");
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = scanner.nextDouble();
}
}
return array;
}
public static double[][] printMartix(double[][] array) {
System.out.println("数组的值是");
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
return array;
}
public static double[][] addMartix(double[][] arr1, double[][] arr2) {
double tmp[][] = new double[3][3];
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1.length; j++) {
tmp[i][j] = arr1[i][j] + arr2[i][j];
}
}
return tmp;
}
public static void main(String[] args) {
double[][] arr1 = new double[3][3];
double[][] arr2 = new double[3][3];
double[][] tmp = new double[3][3];
setMartix(arr1);
setMartix(arr2);
printMartix(arr1);
printMartix(arr2);
tmp = addMartix(arr1, arr2);
printMartix(tmp);
System.out.println(arr1.length);
}
}
4 二维数组的平均值
public class Homewordk {
public static double[] setMatrix(double[] array) {
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < array.length; i++) {
array[i] = scanner.nextDouble();
}
return array;
}
public static double average(double[] array) {
double average, sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
average = sum / array.length;
return average;
}
public static void main(String[] args) {
double[] array = new double[6];
setMatrix(array);
System.out.println("平均值是" + average(array));
}
}
5二维数组计算三维空间上距离最近的两个点
public class Homewordk {
/*
计算两点之间的距离
*/
public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
double distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
return distance;
}
public static double[][] getArray(double[][] array) {
Scanner input = new Scanner(System.in);
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = input.nextDouble();
}
}
return array;
}
public static void main(String[] args) {
/*
输入数值
*/
System.out.println("输入6个x,y,z");
double[][] array = new double[6][3];
getArray(array);
int p0 = 0, p1 = 1;
double minDis = distance(array[p0][0], array[p0][1], array[p0][2], array[p1][0], array[p1][1], array[p1][2]);
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
double dis = distance(array[i][0], array[i][1], array[i][2], array[j][0], array[j][1], array[j][2]);
if (dis < minDis) {
p0 = i;
p1 = j;
minDis = dis;
}
}
}
System.out.println("最短的距离是" + minDis);
System.out.println("最近的两个点是(" + array[p0][0] + array[p0][1] + array[p0][2] + ")" + "(" + array[p1][0] + array[p1][1] + array[p1][2] + ")");
}
}
其实有些时候真的很奇妙,你的父母真的跟你说不通
他们就是要你结婚要你生孩子 他没有任何其他的人生追求 她的思想眼界就是狭窄和无知
她就是想控制你 你的人生你的追求好像全部都是在结婚生子上面 你的人生经历你的未来
她完全不管不关心 他也不能理解 好烦
过好自己的人生不可以么