再来一道JAVA测试题(没耐心的别进来)
呵呵,鉴于前一个测试的帖子人气这么好,偶就再接再厉,再发一道关于异常处理的测试。是我们java练习课的一道大题,不过偶做的还不错。建议:大家先喝一杯咖啡或者可乐,然后屏心静气,拿出10分钟的时间来搞定它。(这道题嵌套的子块太多,打印下来分析比较不错,doc文件在附件里)
问:输出结果是什么?(想拿上机编译的人建议就不要看下去了,浪费时间)
class Uebung extends Exception {
} // Beschreibt einen neuen Exception-Typ
public class Alarm_Alarm {
static void GrossAlarm(int i) throws Uebung {
if(( i/(i%2) )==1) throw new Uebung();
System.out.println(„leichtsinnig");
}
static void FeuerAlarm() {
try {
GrossAlarm(7%5);
} catch(Exception e) {
System.out.println("man");
try {
GrossAlarm(7%6);
} catch(Uebung u) {
System.out.println("spielt");
}
}
}
static void FehlAlarm() throws Uebung {
try {
int wasSolls;
if (true&false) {
wasSolls = 0;
} else {
wasSolls = 1;
}
Alarmuebung(wasSolls);
} catch (Uebung e) {
System.out.println(„feuer");
} catch(Exception e) {
System.out.println("Streichhoelzern");
} finally{
int wasSolls;
if (false&&true) {
wasSolls = 0;
} else {
wasSolls = 2;
}
Alarmuebung(wasSolls);
}
}
static void Alarmuebung(int i) throws Uebung {
switch(i) {
case 1:
System.out.println(„mit");
default:
throw new Uebung();
}
}
public static void main(String[] argv) throws Uebung {
try{
FeuerAlarm();
System.out.println("nicht");
FehlAlarm();
} catch (ArithmeticException e) {
System. out .println("kerzen");
} catch (Exception e) {
System.out.println("");
}
}
} man spielt nicht mir feuer 真是像楼上的说的一样吗? 没错,热线里真是人才济济阿
ist Java so heiss moment in Comuter science?
Ich denke shcon,also,wirkann hier java lernen und diskutieren. ich bin auch angefangen. : )回复: ist Java so heiss moment in Comuter science?
最初由 lf_leon 发布Ich denke ...
很好,你先查一下构造函数的特点,然后去把我在JAVA区发的那个java类测试做做先
页:
[1]