exercise2_9.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 41 行

JAVA
41
字号
// Exercise2_9.java
import javax.swing.JOptionPane;

public class Exercise2_9 {
  /**Main method*/
  public static void main(String[] args) {
    // Enter the first edge
    String numberString = JOptionPane.showInputDialog(null,
      "Enter the first edge length (double)",
      "Exercise2_9 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)",
      "Exercise2_9 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)",
      "Exercise2_9 Input", JOptionPane.QUESTION_MESSAGE);

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

    // Display results
    System.out.println("Can edges " + edge1 + ", " + edge2 + ", and "
      + edge3 + " form a triangle? " + (
      (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) &&
      (edge2 + edge3 > edge1)));

    System.exit(0);
  }
}

⌨️ 快捷键说明

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