📄 normtest.java
字号:
package linearEquationGroup;
import java.util.Scanner;
public class NormTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n;
double[] vector;
double[][] matrix;
String vOrM;
String another = "y";
System.out
.println("\nthe program compute the norm of a vector or a matrix.\n");
do {
System.out.println("input v as vector,m as matrix:");
vOrM = input.next();
if (!vOrM.equalsIgnoreCase("v") && !vOrM.equalsIgnoreCase("m")) {
System.out.println("don't input any else!");
continue;
} else if (vOrM.equalsIgnoreCase("v")) {
System.out.println("input the vector's dimension:");
n = input.nextInt();
vector = new double[n + 1];
System.out
.println("input the elements of the vector(use space to seperate):");
for (int i = 1; i < n + 1; i++)
vector[i] = input.nextDouble();
System.out.println("the one-norm of the vector:"
+ Norm.vectorOne(n, vector));
System.out.println("the two-norm of the vector:"
+ Norm.vectorTwo(n, vector));
System.out.println("the infinitive-norm of the vector:"
+ Norm.vectorInfinitive(n, vector));
} else {
System.out.println("input the matrix's level:");
n = input.nextInt();
matrix = new double[n + 1][n + 1];
System.out
.println("left to right,up to down,"
+ "input the elements of the matrix(use space to seperate):");
for (int i = 1; i < n + 1; i++)
for (int j = 1; j < n + 1; j++)
matrix[i][j] = input.nextDouble();
System.out.println("the one-norm of the matrix:"
+ Norm.matrixOne(n, matrix));
System.out.println("(not right)the two-norm of the matrix:"
+ Norm.matrixTwo(n, matrix));
System.out.println("the infinitive-norm of the matrix:"
+ Norm.matrixInfinitive(n, matrix));
}
System.out
.println("\n input another vector or matrix? y/n:");
another = input.next();
} while (another.equalsIgnoreCase("y"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -