• 作业


    package com;
    
    public class hello {
        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 co;
    
    import java.util.*;
    
    public class hello{
        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 com;
    
    
    
    public class hello {
        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 com;
    
    
    
    public class hello {
        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);
        }
    }
  • 相关阅读:
    菜鸟二三事
    访问 IIS 元数据库失败的问题(转)
    SQL Server 2005/2008还原数据库时遇到的问题(转)
    ME54N审批、撤批触发增强点:ME_RE…
    南通网站建设整理:最新搜索引擎登录口保证都可以用
    调试mvc的源代码
    c#委托(delegate)揭秘
    ASP.NET 应用程序生命周期概述
    JavaScript Array(数组)对象
    jQuery.each
  • 原文地址:https://www.cnblogs.com/zhangjun19991118/p/12710231.html
Copyright © 2020-2023  润新知