zoukankan      html  css  js  c++  java
  • 学习Java的第02天

    第二天主要学习内容数组!

    1.数组的高级算法以及数组的低级算法。

    低级算法:

    ①交换:交换有两种方式的交换,一种是以倒叙输出,一种是前后交换位置,代码实现如下:

    第一种:

    double[] arr={10.3,8,6,4.2,2};
    for (int i = 4; i >=0; i--) {
    System.out.print(arr[i]+" ");
    }

    第二种:

    for(int star=0,end= arr.length-1;star<end;star++,end--){
    double temp=arr[star];
    arr[star]=arr[end];
    arr[end]=temp;
    }
    for (int i = 0; i < arr.length; i++) {
    System.out.print(arr[i]+" ");
    }

    ②复制

    package com.day_02;

    public class szfz {
    public static void main(String[] args) {
    int[] a={1,23,4};
    int[] b={8,9,12};
    int[] c=new int[a.length+b.length];
    for (int i=0; i <a.length ; i++) {
    c[i]=a[i];
    // System.out.println(c[i]);

        }
    
        for (int n=0,j=a.length;n<j; n++,j++) {
            c[j]=b[n];
            //System.out.println(c[j]);
    
        }
    
        for (int i = 0; i <c.length ; i++) {
            System.out.println(c[i]);
    
        }
    

    ③求和:简单的遍历求和相加。

    ④合并:就是相加问题,创建三个数组,将数组a的长度用作b的循环加进去。

    高级算法

    排序中用到的冒排序

    package com.day_02;

    import java.util.Scanner;

    public class zy6 {
    public static void main(String[] args) {
    int[] a=new int[6];
    Scanner sc= new Scanner(System.in);
    for (int i = 0; i < a.length; i++) {
    int b=sc.nextInt();
    a[i]=b;
    }
    for (int i = 0; i < a.length-1; i++) {
    for(int j=1;j<a.length;j++){
    int tpme=a[i];
    a[i]=a[j];
    a[j]=tpme;
    }
    System.out.print(a[i]+" ");

        }
    
    }
    

    }

  • 相关阅读:
    tushare包使用案例
    Matplotlib模块:绘图和可视化
    pandas使用
    django 表操作
    元数据Meta
    django关系类型字段
    django项目模型字段
    django项目mysite 2
    django安装使用xadmin
    GCC版本中没有GLIBCXX_3.4.15错误
  • 原文地址:https://www.cnblogs.com/cxrblog/p/13927391.html
Copyright © 2011-2022 走看看