⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise5_13.java

📁 Introduction to java programming 一书中所有编程练习部分的源码
💻 JAVA
字号:
public class Exercise5_13 {  public static void main(String[] args) {    // Initialize the list    double[] myList = {5.0, 4.4, 1.9, 2.9, 3.4, 3.5};    // Print the original list    System.out.println("My list before sort is: ");    printList(myList);    // Sort the list    selectionSort(myList);    // Print the sorted list    System.out.println();    System.out.println("My list after sort is: ");    printList(myList);  }  /** The method for printing numbers */  static void printList(double[] list) {    for (int i = 0; i < list.length; i++)      System.out.print(list[i] + "  ");    System.out.println();  }  /** The method for sorting the numbers */  static void selectionSort(double[] list) {    double currentMin;    int currentMinIndex;    for (int i = 0; i < list.length; i++) {      // Find the smallest in the list[i..list.length-1]      currentMin = list[i];      currentMinIndex = i;      for (int j = i + 1; j < list.length; j++) {        if (currentMin > list[j]) {          currentMin = list[j];          currentMinIndex = j;        }      }      // Swap list[i] with list[currentMinIndex] if necessary;      if (currentMinIndex != i) {        list[currentMinIndex] = list[i];        list[i] = currentMin;      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -