20209/29
今天学习随机数,和JOptionPane的一些使用
//An addition program import javax.swing.JOptionPane; // import class JOptionPane public class Addition { public static void main( String args[] ) { 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 } }
//JOptionPane方便用户提供值时弹出标准对话框;JOptionPane.showInputDialog窗口显示,读取数据用字符串类型;
//Integer.parseInt()是把()里的内容转换成整数
//showConfirmDialog():确认对话框
//showInputDialog():输入对话框
//showMessageDialog():消息对话框
//showOptionDialog():选择对话框
二.随机数不重复还有什么简单方法
三.动手动脑