程序实现了自定义数组(多少行,多少列),并输出数组。
代码如下:
import java.util.Scanner;
class q {
public static void main(String[] args) {
// 确定数组
int x = 0, y = 0, z = 0, i = 0;
Scanner input = new Scanner(System.in);
System.out.println("h = ?");
z = input.nextInt();
System.out.println("s = ?");
i = input.nextInt();
z = z + 1;
int a[][] = new int[i][z];
// 输出数组样式
System.out.println("");
System.out.println("赋值前的数组");
System.out.println("");
for (x = 0; x < i; x++) {
for (y = 0; y < z; y++) {
System.out.print("a[" + x + "][" + y + "]" + " ");
}
System.out.println("");
}
// 输入数组的值
System.out.println("");
System.out.println("请给数组赋值");
System.out.println("");
for (x = 0; x < i; x++) {
for (y = 0; y < z; y++) {
System.out.println("a[" + x + "][" + y + "]" + " = ?");
a[x][y] = input.nextInt();
}
}
System.out.println("");
System.out.println("赋值后的数组");
System.out.println("");
// 输出赋值后的数组
for (x = 0; x < i; x++) {
for (y = 0; y < z; y++) {
System.out.print(a[x][y] + " ");
}
System.out.println("");
}
}
}
=======================