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

📄 exercise3_2.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 JAVA
字号:
// Exercise3_2.java: Sort three numbers
// The solution can be simplified after you how sort a list
import javax.swing.JOptionPane;

public class Exercise3_2 {
  public static void main(String[] args) {
    // Enter the first number
    String numberString = JOptionPane.showInputDialog(null, 
      "Enter the first integer:",
      "Exercise3_2 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to int
    int num1 = Integer.parseInt(numberString);    
    
    // Enter the second number
    numberString = JOptionPane.showInputDialog(null, 
      "Enter the second integer:",
      "Exercise3_2 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to int
    int num2 = Integer.parseInt(numberString);    
    
    // Enter the third number
    numberString = JOptionPane.showInputDialog(null, 
      "Enter the third integer:",
      "Exercise3_2 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to int
    int num3 = Integer.parseInt(numberString);    
		
    if (num1 > num2) {
      int temp = num1;
      num1 = num2;
      num2 = temp;
    }

    if (num2 > num3) {
      int temp = num2;
      num2 = num3;
      num3 = temp;
    }

    if (num1 > num2) {
      int temp = num1;
      num1 = num2;
      num2 = temp;
    }

    System.out.println("The sorted numbers are "
      + num1 + " " + num2 + " " + num3);
    
    System.exit(0);
  }
}

⌨️ 快捷键说明

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