java矩阵这么键盘输入?
1个回答
展开全部
你好,实例代码如下,希望你可以受到启发:
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.print("请输入矩阵的行高:");
int a = sc.nextInt() ;
System.out.print("请输入矩阵的列宽:");
int b = sc.nextInt() ;
double[][] x = new double[a][b] ;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
System.out.print("请输入元素x["+i+"]["+j+"]的值:" );
x[i][j] = sc.nextDouble() ;
}
}
print(x) ;
}
public static void print(double[][] x){
System.out.println("您输入的矩阵为:");
for(int i=0;i<x.length;i++){
for(int j=0;j<x[i].length;j++){
System.out.print(x[i][j] + " ") ;
}
System.out.println();
}
}
}
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.print("请输入矩阵的行高:");
int a = sc.nextInt() ;
System.out.print("请输入矩阵的列宽:");
int b = sc.nextInt() ;
double[][] x = new double[a][b] ;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
System.out.print("请输入元素x["+i+"]["+j+"]的值:" );
x[i][j] = sc.nextDouble() ;
}
}
print(x) ;
}
public static void print(double[][] x){
System.out.println("您输入的矩阵为:");
for(int i=0;i<x.length;i++){
for(int j=0;j<x[i].length;j++){
System.out.print(x[i][j] + " ") ;
}
System.out.println();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询