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

📄 exercise3_3.java

📁 java程序设计 机械工业出版社 书籍代码
💻 JAVA
字号:
// Exercise3_3: Compute income tax
import javax.swing.JOptionPane;

public class Exercise3_3 {
  /** Main method */
  public static void main(String[] args) {
    // Enter the first edge
    String numberString = JOptionPane.showInputDialog(null,
      "Enter the first edge length (double)",
      "Exercise3_3 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to double
    double edge1 = Double.parseDouble(numberString);

    // Enter the second edge
    numberString = JOptionPane.showInputDialog(null,
      "Enter the second edge length (double)",
      "Exercise3_3 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to double
    double edge2 = Double.parseDouble(numberString);

    // Enter the third edge
    numberString = JOptionPane.showInputDialog(null,
      "Enter the third edge length (double)",
      "Exercise3_3 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to double
    double edge3 = Double.parseDouble(numberString);

    // Display results
    boolean valid = (edge1 + edge2 > edge3) &&
      (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1);

    if (valid) {
      System.out.println("The perimeter of the triangle is " +
        (edge1 + edge2 + edge3));
    }
    else
      System.out.println("Input is invalid");

    System.exit(0);
  }
}

⌨️ 快捷键说明

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