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

    1.定义长度位5的整型数组,输入他们的值,用冒泡排序后输出.

    package com.run.test;
    
    import java.util.Scanner;
    
    public class One {
     
        public static void main(String[] args) {
            int[] num = new int[5];
            Scanner input = new Scanner(System.in);
            for (int i = 0; i < num.length; i++) {
                num[i] = input.nextInt();
            }
            for (int i = 0; i < num.length - 1; i++) {
                for (int j = 0; j < num.length - 1 - i; j++) {
                    if (num[j] > num[j + 1]) {
                        int temp = num[j];
                        num[j] = num[j + 1];
                        num[j + 1] = temp;
                    }
                }
            }
            for (int i = 0; i < num.length; i++) {
                System.out.print(num[i] + " ");
            }
     
        }
     
    }

    2.定义数组{34,22,35,67,45,66,12,33},输入一个数a,查找在数组中是否存在,如果存在,输出下标,不存在输出"not found"

    import java.util.Scanner;
    
    public class One {
     
         public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                boolean flag= false;
                int[] b = {34,22,35,67,45,66,12,33};
                System.out.print("请输入一个数:");
                int a = input.nextInt();
                for (int i = 0; i < b.length; i++) {
                    if (b[i] == a) {
                        System.out.println("该数的下标是:" + i);
                        flag = true;
                    }
                }
                    if(flag == false){
                        System.out.println("not found");
                    }
            }
     
    }

    3.以矩阵的形式输出一个double型二维数组(长度分别为5、4,值自己设定)的值。

    public class One {
     
        public static void main(String[] args) {
    
            double[][] a = { { 1.1, 3.2, 5.3, 7.4 }, { 9.1, 11,2, 13.3, 15.4 },
                    { 17.1, 19.2, 21.3, 23.4 }, { 25.1, 27.2, 29.3, 31.4 },
                    { 33, 35, 37, 39 } };
                    for (int i = 0; i < a.length; i++) {
                    for (int j = 0; j < a.length - 1; j++) {
                    System.out.print(a[i][j] + "	");
                    }
                    System.out.println(" ");
                }
            } 
     
    }

    4.定义一个二维数组(长度分别为3,4,值自己设定),求该二维数组的最大值.

    public class One {
     
        public static void main(String[] args) {
            int[][] arr = {{11,22,33,44},{15,25,35,45},{69,66,99,96}};
            int max = arr[0][0];
            for(int i = 0;i<arr.length;i++) {
                for(int j = 0;j< arr[i].length;j++) {
                    if(arr[i][j]>max) {
                        max = arr[i][j];
                    }
                }
            }System.out.println(max);
        } 
     
    }
  • 相关阅读:
    linux下RTP编程(使用JRTPLIB)(转)
    omap 移植qt4.7.0
    mknod指令详解
    mplayer 在线播放错误
    移植Mplayer到OK6410开发板
    海量数据处理算法—Bit-Map
    海量数据面试题----分而治之/hash映射 + hash统计 + 堆/快速/归并排序
    并行、并发、同步和互斥
    阿里巴巴集团2014年校园招聘北京笔试题
    动态规划之矩阵连乘
  • 原文地址:https://www.cnblogs.com/rozenscarlet/p/12710046.html
Copyright © 2011-2022 走看看