findthemaximum.java

来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 31 行

JAVA
31
字号
import javax.swing.*;
public class FindTheMaximum
{
  public static void main(String[] args)
  {
    String s1, outMessage;
    
    double firstnum, secnum, max;
    s1 = JOptionPane.showInputDialog("Enter a number:");
    firstnum = Double.parseDouble(s1);
    s1 = JOptionPane.showInputDialog("Great! Please enter a second number:");
    secnum = Double.parseDouble(s1);
    max = findMaximum(firstnum, secnum); // the method is called here
    JOptionPane.showMessageDialog(null, 
            "The maximum of the two numbers is " + max, 
            "Maximum Value", JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
  }
    // following is the method findMaximum()
  public static double findMaximum(double x, double y)
  {                  // start of method body
    double maxnum;      // variable declaration
    if (x >= y)      // find the maximum number
      maxnum = x;
    else
      maxnum = y;
    
    return maxnum;                                          
  }  // end of method body and end of method
}

⌨️ 快捷键说明

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