• 4_16


    package hm_4_16;
    /*
     * 第一题升序排列
     */
    import java.util.Arrays;
    
    public class test01 {
    
        public static void main(String[] args) {
            int[] arr = {26,36,96,25,6};
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr.length-1-i; j++) {
                    if (arr[j]>arr[j+1]) {
                        int a = arr[j];
                        arr[j]=arr[j+1];
                        arr[j+1]=a;
                    }
                }
            }
            System.out.println(Arrays.toString(arr));
        }
    
    }
    package hm_4_16;
    
    import java.util.Scanner;
    
    /*
     * 定义数组数输入值查看时否在数组里
     */
    public class test02 {
    
        public static void main(String[] args) {
            int[] arr = {26,36,96,25,6,88};
            Scanner sca= new Scanner(System.in);
            System.out.println("输入一个数:");
            int  a = sca.nextInt();
            for (int i = 0; i < arr.length; i++) {
                if (arr[i]==a) {
                    System.out.println("下标为:"+i);
                    return;
                }
            }
            System.out.println("Not Found");
            
                
        }
    
    }
    package hm_4_16;
    /*
     * 矩阵
     */
    public class test03 {
    
        public static void main(String[] args) {
            int arr[][] = {{1,5,9,6},{96,32,45,61},{11,24,36,45}}; 
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j]+" ");
                }
                System.out.println();
    //            System.out.println("---");
            }
        }
    
    }
    package hm_4_16;
    /*
     * 求二维数组最大值
     */
    public class test04 {
    
        public static void main(String[] args) {
            int arr[][] = {{1,5,9,6},{96,32,45,61},{11,24,36,45}}; 
            int max =arr[0][0];
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    if (max<arr[i][j]) {
                        int a= max;
                        max=arr[i][j];
                        arr[i][j]=a;
    //                    System.out.println(arr[i][j]);
                    }
                }
            }
            System.out.println(max);
        }
    
    }
  • 相关阅读:
    2018 桂林ccpc现场赛 总结
    2018 南京icpc现场赛总结
    nowcoder 203J Graph Coloring I(dfs)
    nowcoder 203A Knight(贪心+打表)
    nowcoder 202H-卡牌游戏
    nowcoder 202F-平衡二叉树
    topcoder srm 738 div1 FindThePerfectTriangle(枚举)
    codeforces 1041 E.Vasya and Good Sequences(暴力?)
    hdu 3507 Print Article(dp+斜率优化)
    hdu 1007 Quoit Design(分治)
  • 原文地址:https://www.cnblogs.com/wzm7282/p/12702826.html
Copyright © 2020-2023  润新知