Day29-20260125

复习巩固

java 复制代码
package com.array;

import java.util.Arrays;

public class Man3 {
            /*
        0  0  0  22 0  0  15
        0  11 0  0  0  17 0
        0  0  0  -6 0  0  0
        0  0  0  0  0  39 0
        91 0  0  0  0  0  0
        0  0  28 0  0  0  0
         */
    public static void main(String[] args){
        int[][] array1 = new int[6][7];//稀疏数组
        array1[0][3]=22;
        array1[0][6]=15;
        array1[1][1]=11;
        array1[1][5]=17;
        array1[2][3]=-6;
        array1[3][5]=39;
        array1[4][0]=91;
        array1[5][2]=28;
//        for (int i = 0; i < 6; i++) {
//            for (int j = 0; j < 7; j++) {
//                System.out.print(array1[i][j]+"\t");
//            }
//            System.out.println();
//        }
        for (int[] ints : array1) {
            for (int anInt : ints) {
                System.out.print(anInt+"\t");
            }
            System.out.println();
        }
        int sum = 0;
        for (int i = 0; i <array1.length; i++) {
            for (int j = 0; j < array1[i].length; j++) {
                if (array1[i][j]!=0){
                    sum++;
                }
            }
        }
        System.out.println("sum="+sum);
        int count = 0;
        int[][] array2 = new int[sum+1][3];
        array2[0][0]=6;
        array2[0][1]=7;
        array2[0][2]=sum;
        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j < array1[i].length; j++) {
                if (array1[i][j]!=0) {
                    count++;
                    array2[count][0] = i;
                    array2[count][1] = j;
                    array2[count][2] = array1[i][j];
                }
            }
        }
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i][0]+"\t"
                    +array2[i][1]+"\t"
                    +array2[i][2]+"\t");
        }
        System.out.println();
        int[][] array3 = new int[array2[0][0]][array2[0][1]];
        for (int i = 1; i < array2.length; i++) {
            array3[array2[i][0]][array2[i][1]]=array2[i][2];
        }
        for (int i = 0; i < array3.length; i++) {
            for (int j = 0; j < array3[i].length; j++) {
                System.out.print(array3[i][j]+"\t");
            }
            System.out.println();
        }
        System.out.println("++++++++++++++++++++++++++");
        int[] a = {1,4,5,6,72,2,2,2,25,6,7};//冒泡排序
        int[] sort = sort(a);
        System.out.println(Arrays.toString(sort));
    }
    public static int[] sort(int[] array){
        int temp =0;
        for (int i = 0; i < array.length-1; i++) {
            boolean flag = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j+1]<array[j]){
                    temp = array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                    flag = true;
                }
            }
            if (flag==false){
                break;            }

        }
        return array;
    }
}
java 复制代码
0	0	0	22	0	0	15	
0	11	0	0	0	17	0	
0	0	0	-6	0	0	0	
0	0	0	0	0	39	0	
91	0	0	0	0	0	0	
0	0	28	0	0	0	0	
sum=8
6	7	8	
0	3	22	
0	6	15	
1	1	11	
1	5	17	
2	3	-6	
3	5	39	
4	0	91	
5	2	28	

0	0	0	22	0	0	15	
0	11	0	0	0	17	0	
0	0	0	-6	0	0	0	
0	0	0	0	0	39	0	
91	0	0	0	0	0	0	
0	0	28	0	0	0	0	
++++++++++++++++++++++++++
[1, 2, 2, 2, 4, 5, 6, 6, 7, 25, 72]

进程已结束,退出代码为 0
相关推荐
一条大祥脚3 分钟前
Codeforces Round 1099 (Div. 2) 构造|贪心|图论|还原数组
java·算法·图论
yaoxin5211237 分钟前
414. Java 文件操作基础 - 批量压缩与索引:将154首十四行诗高效存储为带目录的二进制文件
java·windows·python
超梦dasgg9 分钟前
详细讲解:WebMvcConfigurer 接口
java·开发语言·spring
JAVA社区19 分钟前
Java进阶全套教程(三)—— Spring框架核心精讲
java·开发语言·spring·面试·职场和发展·mybatis
Sheldon Chao20 分钟前
Lecture 7 基于策略梯度的算法
人工智能·算法·机器学习
始三角龙25 分钟前
LeetCode hoot 100 -- 缺失的第一个正整数
算法·leetcode·职场和发展
彭于晏Yan31 分钟前
OkHttp 与 RestTemplate 技术选型对比
java·spring boot·后端·okhttp
飞Link40 分钟前
深度解析孪生网络(Siamese Network):从原理、技巧到实战应用
算法·数据挖掘·回归
金銀銅鐵41 分钟前
[Java] 如何理解 class 文件中字段的 descriptor?
java·后端
500841 小时前
Graph Engine 是什么,为什么需要它
java·人工智能·性能优化·ocr·wpf