zoukankan      html  css  js  c++  java
  • 第六次作业

    1定义数组冒泡排序

    package ffff;
    import java.util.*;
    public class gggg {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int []a=new int[5];
            Scanner input=new Scanner(System.in);
            for (int i = 0; i < a.length; i++) {
                int x=input.nextInt();
                a[i]=x;
                
                
            }
            for (int i = 0; i < a.length-1; i++) {
                for (int j = 0; j < a.length-1-i; j++) {
                    if(a[j]>a[j+1]){
                        int temp=a[j];
                        a[j]=a[j+1];
                        a[j+1]=temp;
                    }
                }
            }
            for (int i = 0; i < a.length; i++) {
                System.out.println(a[i]+"");
            }            
             
        }
    }

    2查找

    package ffff;
    import java.util.*;
    public class gggg {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int []a={34,22,35,67,45,66,12,33};
            int c=0;
            Scanner input=new Scanner(System.in);
            System.out.println("输入一个数");
            int x=input.nextInt();
            for (int i = 0; i < a.length; i++) {
                
                if(x==a[i]){
                    c=1;
                    System.out.println(i);
                }
                
            }
            if(c==0){
                System.out.println("no");
            }
             
        }
    }

    3数组

    package ffff;
    
    public class gggg {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            double[][]a={{1,2,3,4},{5,6,7,8},{56,44,74,88},{5,65,23,11},{45,55,85,42}};
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 4; j++) {
                    System.out.print(a[i][j]+"");
                }
                System.out.println();
            }
             
        }
    }

    最大值

    package ffff;
    
    public class gggg {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int[][]a={{1,2,3,4},{5,6,7,8},{56,44,74,88}};
            int max=0;
            
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 4; j++) {
                    if(a[i][j]>max){
                        max=a[i][j];
                        
                        
                    }
                }
                
            }
             System.out.println(max);
        }
    }
  • 相关阅读:
    thymeleaf时间戳转换
    alerttemplate 时间戳转换
    jQuery.Deferred exception: a.indexOf is not a function TypeError: a.indexOf is not a function
    区分数据是对象还是字符串
    eclipse中选取一列快捷键
    图片拉伸不变型
    这里ajax需要改成同步
    idea如何整理代码格式
    20170311-起早床
    20190310-解决头屑
  • 原文地址:https://www.cnblogs.com/xxy02160216/p/12686097.html
Copyright © 2011-2022 走看看