/**
* ClassName:test01
* Package:JavaSECode
* Description:案例1:获取数组arr中的所有元素的和。
* 提示:使用for嵌套循环即可。
*
* @Author LYQ
* @Create 2023/10/29 21:32
* @Version 1.0
*/
public class test01 {
public static void main(String[] args) {
// 声明并定义二维数组
int[][] arr=new int[][]{{1,2,1},{2,1},{4}};
int sum=0;
for(int i=0;i<arr.length;i++){
for (int j=0;j<arr[i].length;j++){
sum+=arr[i][j];
}
}
System.out.println("二维数组中所有数字和为:"+sum);
}
}
public class test02 {
public static void main(String[] args){
// 定义一个二维数组
String [][] employees={
{"10","1","段誉","22","3000"},
{"13","2","令狐冲","32","18000","15000","2000"},
{"11","3","任我行","23","7000"},
{"11","4","张三丰","22","3000"},
{"12","5","周芷若","22","3000"},
{"11","6","赵敏","22","3000"},
{"12","7","张无忌","22","3000"},
{"13","2","韦小宝","32","18000","15000","2000"},
{"13","2","杨过","32","18000","15000","2000"},
{"13","2","小龙女","32","18000","15000","2000"},
{"13","2","郭靖","32","18000","15000","2000"},
{"13","2","黄蓉","32","18000","15000","2000"},
};
System.out.println("员工类型\t编号\t姓名\t年龄\t薪资\t奖金\t股票\t");
for(int i=0;i<employees.length;i++){
// 获取数组首位数字
String employeeTypes=employees[i][0];
switch (employeeTypes){
case "10":
System.out.print("普通职员");
break;
case "11":
System.out.print("程序员");
break;
case "12":
System.out.print("设计师");
break;
case "13":
System.out.print("架构师");
break;
}
for(int j=1;j<employees[i].length;j++){
System.out.print(employees[i][j]+"\t");
}
System.out.println();
}
}
}