• day07


    01

     1 package com.tedu.demo;
     2 
     3 public class ArrayMethodTest_01 {
     4 
     5     /**
     6      * 
     7      */
     8     public static void main(String[] args) {
     9         int[] arr = {1,3,56,45,23,78};
    10 //        selectSort(arr);
    11         bubbleSort(arr);
    12         printArray(arr);
    13         
    14     }
    15     
    16     //定义方法:实现冒泡排序
    17     public static void bubbleSort(int[] arr){
    18         for(int i=0;i<arr.length-1;i++){
    19             for(int j=0;j<arr.length-i-1;j++){
    20                 if(arr[j]>arr[j+1]){
    21                     int temp = arr[j];
    22                     arr[j] = arr[j+1];
    23                     arr[j+1] = temp;
    24                 }
    25             }
    26         }
    27     }
    28 
    29     /*
    30      * 定义方法,实现数组的选择排序 
    31      *     返回值: 没有
    32      *  参数: 数组 
    33      * 实现步骤: 
    34      *         1.嵌套循环实现排序 外循环,控制的是一共比较了多少次
    35      *                          内循环,控制的是每次比较了多少个元素 
    36      *         2. 判断元素的大小值 小值,存储到小的索引
    37      */
    38     public static void selectSort(int[] arr) {
    39         for (int i = 0; i < arr.length-1; i++) {
    40             for (int j = i + 1; j < arr.length; j++) {
    41                 if(arr[i]>arr[j]){
    42                     int temp = arr[i];
    43                     arr[i] = arr[j];
    44                     arr[j] = temp;
    45                 }
    46             }
    47         }
    48         
    49     }
    50     
    51     //定义方法:实现数组遍历
    52     public static void printArray(int[] arr){
    53         for(int i=0;i<arr.length;i++){
    54             System.out.print(arr[i]+" ");
    55         }
    56         System.out.println();
    57     }
    58 
    59 }

    02

    package com.tedu.demo;
    
    /*
     * 数组的逆序:
     *         数组中的元素,进行位置上的交换
     *         逆序不等于反向遍历
     *         就是数组中最远的两个索引,进行位置交换,实现数组逆序
     *         使用的数组的指针思想,就是变量思想,可以随时变换索引
     * 数组逆序的实现思想:数组最远端的位置交换
     * 数组的指针思想:
     *         就是数组的索引
     *         指针是可以随时指向数组的任意一个索引的
     * 
     * */
    
    public class ArrayMethodTest {
        public static void main(String[] args) {
            int[] arr = { 1, 2, 3, 4 };
            //调用数组逆序的方法,传递数组参数
            printArray(arr);
            for (int i = 0; i < arr.length; i++) {
                System.out.println(arr[i]);
            }
    
        }
    
        // 定义方法:实现数组的逆序
        public static void printArray(int[] arr) {
            // 定义两个整数变量用来代替最小的下标,和最大的下标
            // 当min<max,执行程序,当min>=max时,结束位置交换
            for (int min = 0, max = arr.length - 1; min < max; min++, max--) {
                // 定义第三个变量,用来保存min或者max,防止交换是数据被覆盖
                int index = arr[min];
                arr[min] = arr[max];
                arr[max] = index;
    
            }
        }
    
    }

    03

    package com.tedu.homework;
    
    public class day07_02 {
    
        /**
         * 倒着打印九九乘法表
         */
        public static void main(String[] args) {
            for(int i=9;i>=1;i--){
                for(int j=1;j<=i;j++){
                    System.out.print(j+"*"+i+"="+j*i+"	");
                }
                System.out.println();
            }
    
        }
    
    }
  • 相关阅读:
    sentinel集群刚开始好的,过几分钟就崩了
    redis主从文件权限问题
    centos7下解决keepalived双机都为master问题
    windows局域网共享文件夹
    最近JS的一些问题
    总结下html、css的一些东西
    Less、一些选择器
    常见布局、媒体查询
    audio标签、HOVER效果、rgba和opacity、隐藏场景
    护工列表页
  • 原文地址:https://www.cnblogs.com/msn-z/p/6963617.html
Copyright © 2020-2023  润新知