「java矩阵输入」Java输出矩形
今天给各位分享java矩阵输入的知识,其中也会对Java输出矩形进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
java怎么输入矩阵
一般情况下都是二维数组咯, 你也可以自己用List等来存储,再用行列来控制输出
java如何输入一个自定义矩阵
java中自定义矩阵:
public static void main(String[] args) {
// TODO Auto-generated method stub
int n= 5;//长度
int array_int[][] = new int[n][n];
//初始化
for(int i=0;in;i++){
for(int j=0;jn;j++){
if(i==0){
if(j%2==0){
array_int[i][j] = (j+1)*(j+1);
}
else{
array_int[i][j] = array_int[i][j-1]+1;
}
}
else if(j==0){
if(i%2==1){
array_int[i][j] = (i+1)*(i+1);
}
else {
array_int[i][j] = array_int[i-1][j]+1;
}
}
else{
if(ij){
if(j%2==0){
array_int[i][j] = array_int[0][j]-i ;
}
else{
array_int[i][j] = array_int[0][j]+i ;
}
}
else{
if(i%2==0){
array_int[i][j] = array_int[i][0]+j ;
}
else{
array_int[i][j] = array_int[i][0]-j ;
}
}
}
//System.out.println(i+" "+j+":"+array_int[i][j] );
}
}
for(int i=0;in;i++){
for(int j=0;jn;j++){
System.out.print(array_int[i][j]+ " " );
}
System.out.println();
}
}
当等于5时的运行结果:
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
java矩阵这么键盘输入?
你好,实例代码如下,希望你可以受到启发:
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;ia;i++){
for(int j=0;jb;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;ix.length;i++){
for(int j=0;jx[i].length;j++){
System.out.print(x[i][j] + " ") ;
}
System.out.println();
}
}
}
关于java矩阵输入和Java输出矩形的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-15,除非注明,否则均为
原创文章,转载请注明出处。