1 2 3 4

10.1日报

今天运行并学习了Addition程序,代码如下:

import javax.swing.JOptionPane;
public class Addition {
 public static void main(String[] args) {
  
  // TODO 自动生成的方法存根
  
  String firstNumber,   // first string entered by user
        secondNumber;  // second string entered by user
 int number1,          // first number to add
     number2,          // second number to add
     sum;              // sum of number1 and number2
 // read in first number from user as a string
 firstNumber =
    JOptionPane.showInputDialog( "Enter first integer" );
 // read in second number from user as a string
 secondNumber =
    JOptionPane.showInputDialog( "Enter second integer" );
 // convert numbers from type String to type int
 number1 = Integer.parseInt( firstNumber );
 number2 = Integer.parseInt( secondNumber );
 // add the numbers
 sum = number1 + number2;
 // display the results
 JOptionPane.showMessageDialog(
    null, "The sum is " + sum, "Results",
    JOptionPane.PLAIN_MESSAGE );
 System.exit( 0 );   // terminate the program
 }
}
 
运行后可弹出窗口页面,输入两个数即可得到和
posted @ 2020-10-01 21:01  小陈的太阳  阅读(82)  评论(0编辑  收藏  举报