Posted on 2007-04-07 22:22
停留的风 阅读(820)
评论(0) 编辑 收藏 所属分类:
Java程序集合
import javax.swing.JOptionPane;//引用包
public class InputDialogDemo
{
public static void main(String[] args)
{
String yearString=JOptionPane.showInputDialog(null,"Enter a year","Example 2.1 Input
(int)",JOptionPane.QUESTION_MESSAGE);
int year=Integer.parseInt(yearString);
//判断是否为瑞年
boolean isLeapYear=((year%4 ==0)&&(year%100!=0))||(year%400==0);
JOptionPane.showMessageDialog(null,year+"is a leap year?"+isLeapYear,"Example 2.1 Output
(int)",JOptionPane.INFORMATION_MESSAGE);
String doubleString=JOptionPane.showInputDialog(null,"Enter a double value","Example 2.1 Input
(double)",JOptionPane.QUESTION_MESSAGE);
double doubleValue=Double.parseDouble(doubleString);
JOptionPane.showMessageDialog(null,doubleValue+"is positive?"+(doubleValue>0),"Example 2.1 Output
(double)",JOptionPane.INFORMATION_MESSAGE);
}
}