用java代码实现一个string的二维数组建立员工表,并进行行列的取值demo
时间: 2024-02-20 09:59:38 浏览: 80
好的,以下是一个简单的 Java 代码,用于创建一个 String 类型的二维数组作为员工表,以及演示如何访问行和列的值:
```java
public class EmployeeTableDemo {
public static void main(String[] args) {
// 创建一个 3 行 4 列的员工表
String[][] employeeTable = {
{"Alice", "25", "Female", "Sales"},
{"Bob", "30", "Male", "Engineering"},
{"Charlie", "40", "Male", "Marketing"}
};
// 访问第二行第三列的值
String gender = employeeTable[1][2];
System.out.println("Gender of employee at row 2, column 3: " + gender);
// 访问第一列所有员工的名字
for (int i = 0; i < employeeTable.length; i++) {
String name = employeeTable[i][0];
System.out.println("Name of employee at row " + (i+1) + ", column 1: " + name);
}
}
}
```
输出结果为:
```
Gender of employee at row 2, column 3: Male
Name of employee at row 1, column 1: Alice
Name of employee at row 2, column 1: Bob
Name of employee at row 3, column 1: Charlie
```
阅读全文