咱们是一个班的啊, 这是我的代码 我把每一个功能都写成了一个函数 有点罗嗦
- class Company {
- public static void main(String[] args) {
- int[][] arr = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
- getAll(arr);
- int sum = getSum(arr);
- System.out.println();
- System.out.println("--------------我是一条快乐的分割线-------------------------");
- System.out.println();
- System.out.println("公司年销售额的总和是: "+sum);
- }
- public static void getAll(int[][] arr){ //遍历数组,并在每一行开头加汉字
- for (int i = 0;i < arr.length ;i++ ) {
- char Han = getHanZi(i+1);
- System.out.print("第"+Han+"季度:"+"\t");
- for (int j = 0;j < arr[i].length ;j++ ) {
- if (j==2) {
- System.out.print(arr[i][j]);
- }else
- System.out.print(arr[i][j]+",");
- }
- System.out.println("");
- }
- }
- public static char getHanZi(int x){ //将对应的数字与大写汉字对应
- char[] arr = {' ','一','二','三','四'};
- return arr[x];
- }
- public static int getSum(int[][] arr){ //遍历数组并求和
- int sum = 0;
- for (int i = 0;i < arr.length ;i++ ) {
- for (int j = 0;j < arr[i].length ;j++ ) {
- sum += arr[i][j];
- }
- }
- return sum;
- }
- }
复制代码
|