zoukankan      html  css  js  c++  java
  • 4.9Java

    1.

    package hello;
    
    public class yes {
         public static void main(String[] args) {
            int [] arr={10,20,30,40,50};
            for(int i=0;i<5;i++){
                System.out.println(arr[i]);
            }
    }
    }

    2.

    package hello;
    
    public class yes {
         public static void main(String[] args) {
              int[] arr = new int[5];
              arr[0]=10;
              arr[1]=20;
              arr[2]=30;
              arr[3]=40;
              arr[4]=50;
              for(int i =0;i<5;i++) {
                  System.out.println(arr[i]);
    }
    }
    }

    3.

    package hello;
    
    public class yes {
         public static void main(String[] args) {
              int[] arr = {23,45,22,33,56};
              double pj = 0;
              int sum =0;
              for(int i =0;i<5;i++) {
                  sum+=arr[i];
              }
              System.out.println("sum="+sum+"平均值为"+sum/5);
    }
    }

    4.

    package hello;
    
    public class yes {
         public static void main(String[] args) {
              int[] arr = {18,25,7,36,13,2,89,63};
              int max =arr[0];
              int q =0;
              for(int i =1;i<arr.length;i++) {
                  if(max < arr[i]) {
                      max = arr[i];
                      q=i;
                  }
              }
              System.out.println("max="+max+"下标"+q);
    }
    }

     5.

    package hello;
    
    public class yes {
         public static void main(String[] args) {
             int[] a= {18,25,7,36,13,2,89,63};
             for(int i=7;i>=0;i--)
             {
               System.out.print("  ");
               System.out.print(a[i]);
             }
    }
    }

    6.

    package hello;
    import java.util.Scanner;
    public class yes {
         public static void main(String[] args) {
             int[] a = { 18,25,7,36,13,2,89,63 };
                System.out.println("原数组的各个元素为:");
                for (int j = 0; j < a.length; j++) {
                    System.out.print(a[j] + "	");
                    if (j == a.length - 1) {
                        System.out.println();
                    }
                }
                System.out.println("请输入要插入的数:");
                int num = 0;
                Scanner s = new Scanner(System.in);
                num = s.nextInt();
         
                int[] b = new int[a.length + 1];
                if (num <= a[0]) {
                    b[0] = num;
                    for (int j = 1; j < b.length; j++) {
                        b[j] = a[j - 1];
                    }
                } else if (num >= a[a.length - 1]) {
                    b[b.length - 1] = num;
                    for (int j = 0; j < b.length - 1; j++) {
                        b[j] = a[j];
                    }
                } else {
                    for (int j = 0; j < a.length - 1; j++) {
                        if (num >= a[j] && num < a[j + 1]) {
                            for (int k = 0; k <= j; k++) {
                                b[k] = a[k];
                            }
                            b[j + 1] = num;
                            for (int m = j + 2; m < b.length; m++) {
                                b[m] = a[m - 1];
                            }
                        }
                    }
                }
         
                System.out.println("现在数组各个元素为:");
                for (int i = 0; i < b.length; i++) {
                    System.out.print(b[i] + "	");
    
                      }
    }
    }
  • 相关阅读:
    h5红包雨
    Reflect
    el-dialog对话弹框中根据后台数据无限制添加el-select标签,并进行展示,搜索,删除
    jQuery伪分页效果
    canvas实现验证码
    jQuery四叶草菜单效果,跟360杀毒软件差不多
    事件
    传参
    在shell script中进行数值运算的两种方法
    为maven插件设置参数的三种方法
  • 原文地址:https://www.cnblogs.com/cmk521/p/12665504.html
Copyright © 2011-2022 走看看