📄 exceptionexample.java
字号:
@SuppressWarnings("serial")
class NolowerLetter extends Exception{
public void print(){
System.out.printf("%c",'#');
}
}
@SuppressWarnings("serial")
class NoDigit extends Exception{
public void print(){
System.out.printf("%c",'*');
}
}
class People{
void printLetter(char c) throws NolowerLetter{
if(c<'a'||c>'z'){
@SuppressWarnings("unused")
NolowerLetter nolowerLetter=new NolowerLetter();
throw( new NolowerLetter());
}
else{
System.out.print(c);
}
}
void printDigit(char c) throws NoDigit{
if(c<'1'||c>'9'){
@SuppressWarnings("unused")
NoDigit noDigit=new NoDigit();
throw(new NoDigit());
}
else{
System.out.print(c);
}
}
}
public class ExceptionExample {
public static void main(String args[]){
People people=new People();
for(int i=0;i<128;i++){
try{people.printLetter((char)i);}
catch(NolowerLetter e){e.print();}
}
for(int i=0;i<128;i++){
try{people.printDigit((char)i);}
catch(NoDigit e){e.print();}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -