• java第六周作业


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

    package day01;
    import java.util.*;
    public class test3 {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input=new
    Scanner (System.in);
    int [] arr=new int [5];
    System.out.println("input");
    for (int i = 0; i < arr.length; i++) {
    arr[i]=input.nextInt();
    }
    for (int i = 0; i < arr.length; i++) {
    for (int j = 0; j < arr.length-i-1; j++) {
    if(arr[j]>arr[j+1]){
    int h=arr[j];
    arr[j]=arr[j+1];
    arr[j+1]=h;
    }
    }
    }
    for (int i = 0; i < arr.length; i++) {
    System.out.println(arr[i]);
    }
    }

    }

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

    import java.util.*;

    public class test3 {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner input=new
            Scanner (System.in);
            int [] arr={34,22,35,67,45,66,12,33};
            int x=0;
            System.out.print("input a=");
            int a=input.nextInt();
            for (int i = 0; i < arr.length; i++) {
                if(a==arr[i]){
                    System.out.println("下标为"+i);
                    x=1;
                }
                 
            }
            if(x==0){
                System.out.println("no found");
            }
             
        }
     
    }
    3.以矩阵的形式输出一个double型二维数组(长度分别为5、4,值自己设定)的值。

    package day01;

    public class yeah {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    double [][] f={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20}};
    for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 5; j++) {
    System.out.print(f[i][j]);

    }System.out.println();
    }
    }

    }

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

    package day01;

    public class yeah {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int [][] ccc={{1,2,3,4},{6,7,8,9},{11,12,13,14}};
    int max=0;
    for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
    if(ccc[i][j]>max)
    max=ccc[i][j];

    }
    }
    System.out.println("max="+max);
    }

    }

  • 相关阅读:
    linux配置Java环境变量(详细)
    linux下的挂载点和分区是什么关系
    VNC的安装与配置
    Linux下的字符集问题
    Freemarker学习中遇到的问题
    ABAP- INCLUDE Zxxx IF FOUND.
    ABAP读取工单状态 STATUS_READ
    WIN7系统设置wifi
    201702-增强记
    20170301 Excel 分多个sheet 导出
  • 原文地址:https://www.cnblogs.com/WB9588/p/12703302.html
Copyright © 2020-2023  润新知