2.36returntest.java

来自「JAVA程序设计的源代码」· Java 代码 · 共 24 行

JAVA
24
字号
import javax.swing.JOptionPane;
public class ReturnTest{
public static void main (String []args){
String temp=JOptionPane.showInputDialog("Input a positive integer:");    //提示用户输入一个正整数
int i=0;
try{
i=Integer.parseInt(temp);
}
catch(Exception e){    //异常信息提示
JOptionPane.showMessageDialog(null,"Error! You should input a integer!","Error",JOptionPane.ERROR_MESSAGE); 
return;    //退出
}
if(i<=0){    //错误信息提示
JOptionPane.showMessageDialog(null,"Error! i<=0!","Error",JOptionPane.ERROR_MESSAGE);
return; 
}
else{
JOptionPane.showMessageDialog(null,"The value of i is valid!","Success",JOptionPane.INFORMATION_MESSAGE);
}
JOptionPane.showMessageDialog(null,"I am  here for testing! \n You have input a valid value!","Success",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);    //退出整个程序
}
}

⌨️ 快捷键说明

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