zoukankan      html  css  js  c++  java
  • 4.10

    //1.定义长度位5的整型数组,输入他们的值用冒泡排序后输出.
    package learn;
    
    public class day06 {
        public static void main(String[] args) {
            int[] a = new int[] { 1, 3, 2, 5, 8 };
            int t;
            for (int i = 0; i < a.length-1; i++) {
                for (int j = 0; j < a.length-1-i;j++) {
                    if (a[j + 1] > a[j]) {
                        t = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = t;
                    }
                }
            }
            for (int j = 0; j < a.length; j++) {
                System.out.print(a[j] + ", ");
            }
        }
    }
    //2定义数组{34,22,35,67 ,45,66,12,33}输入-个数a,查找在数组中是否存在,如果存在,输出下标,不存在输出"not found"
    package learn;
    
    import java.util.*;
    
    public class day06 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int[] n = new int[] { 34, 22, 35, 67, 45, 66, 12, 33 };
            System.out.println("输入一个数");
            int a = input.nextInt();
            int f=0,i,t=0;
            for (i = 0; i < n.length; i++) {
                if (a == n[i]){
                    f=1;
                    t=i;
                    }
            }
            if(f==1){
                System.out.println("存在,下标为:" + t);
                }
            else{
                System.out.println("not found");
            }
    
        }
    }
    //3.以矩阵的形式输出一-个double型二维数组(长度分别为5、4 ,值自己设定)的值。
    package learn;
    
    
    
    public class day06 {
        public static void main(String[] args) {
            double[][] a=new double[5][4];
            for(int i=0;i<5;i++){
                for(int j=0;j<4;j++){
                    System.out.print(a[i][j]+"    ");
                }
                System.out.println();
            }
    
        }
    }
    //4.定义一个二维数组(长度分别为3,4,值自己设定),求该二维数组的最大值.
    package learn;
    
    
    
    public class day06 {
        public static void main(String[] args) {
        
            int[][] a={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
            int t=a[0][0];
            for(int i=0;i<4;i++){
                for(int j=0;j<3;j++){
                    if(a[i][j]>t){
                        t=a[i][j];
                    }
                }
            }
            System.out.println("最大为:"+t);
        }
    }
  • 相关阅读:
    centos7安装jdk8
    centos7安装mysql5.7.31
    docker打包,运行springboot
    centos7安装docker
    ps学习记录
    Html的学习(二)
    tensorflow C++接口调用图像分类pb模型代码
    tensorflow C++接口调用目标检测pb模型代码
    ubuntu14 编译tensorflow C++ 接口
    Python opencv计算批量图片的BGR各自的均值
  • 原文地址:https://www.cnblogs.com/xiaomoa/p/12711042.html
Copyright © 2011-2022 走看看