• 第八次作业


    //1.定义长度位5的整型数组,输入他们的值用冒泡排序后输出.
    package com.a01;
    
    public class hellowold {
        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 com.a01;
    
    import java.util.*;
    
    public class hellowold {
        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.a01;
    
    
    
    public class hellowold {
        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.a01;
    
    
    
    public class hellowold {
        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);
        }
    }

  • 相关阅读:
    Android学习笔记(四十):Preference的使用
    我的Android笔记(十一)——使用Preference保存设置
    Vim简明教程【CoolShell】
    普通人的编辑利器——Vim
    终端shell显示当前git分支_修订版
    代码规范须知_V1.0_20140703
    Android 4.4源码编译过程
    一个帖子学会Android开发四大组件
    什么是软件质量?
    软件配置管理的作用?软件配置包括什么?
  • 原文地址:https://www.cnblogs.com/hyonf/p/12706054.html
Copyright © 2020-2023  润新知