📄 validateinput.java
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Validates the index that the user inputs
* so that the program doesn't abort.
*/
import iopack.Io;
public class ValidateInput{
public static void main(String [] args) {
int [] anArray = {5,6,7};
int index = Io.readInt("Enter an index from 0 to 2");
int value;
if (index >= 0 && index <= 2){
value = anArray[index];
System.out.println("Execution does not get here if index is bad");
}
else
System.out.println("Stick with 0, 1, or 2");
Io.readString("Press any key to exit"); // Added for IDE use
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -