阅读下面程序写出运行结果。 eab
public class Example {
public static void main(String []args){
try{
callMethod();
}catch(Exception e){
System.out.print('a');
}
System.out.println('b');
}
static void createException(){
throw new IndexOutOfBoundsException();
}
static void callMethod(){
try{
createException();
System.out.print('c');
}catch(ArrayIndexOutOfBoundsException e){
System.out.print('d');
}finally{
System.out.print('e');
}
System.out.print('f');
}
}
相关试题
简答题 interface Lookup{ Object find(String name); } class LookupProduct implements Lookup{ private String[] productNames={"Cloth","Bike","Car"}; private Object[] productPrices={new Integer(100),new Integer(200),new Integer(300)}; LookupProduct(){ } public Object find(String name){ for(int i=0;i <productNames.length;i++) if(productNames[i].equals(name)) return productPrices[i]; return null; } } public class LookupDemo{ public void processValues(String[] name,Lookup table){ for(int i=0;i<name.length;i++){ Object value = table.find(name[i]); if(value != null) System.out.println("Product "+name[i]+" Price="+ value); } } public static void main(String[] args){ String[] productArray = {"bike","Car","Paper"}; LookupProduct lp = new LookupProduct(); new LookupDemo().processValues(productArray,lp); }
简答题 阅读程序,写出正确的运行结果。 class test { public static void main(String[] arg){ int a=1,b=6,c=4,d=2; switch (a++) { case 1: c++; d++; case 2: switch (++b) { case 7: c++; case 8: d++; } case 3: c++; d++; break; case 4: c++; d++; } System.out.println(a+","+b+","+c+","+d); } }
简答题 阅读下面程序写出输出结果。 int s; for( int k=5;k<=10;k++) { s=0; for(int m=1;m<k;m++) if(k % m==0) s=s+m; if(s==k) System.out.print(k + “ ”); }
简答题 下面程序运行时输出结果为: C:\ Program Files is a directory。 public class Test { public static void main(String[] args){ File myDir = new File("c:/Program Files"); System.out.println(myDir+myDir.isDirectory()?"is":"isnot"+"a. directory"); } }
简答题 在下面的程序编译之后,按“java J_Test 1 2 3”方式运行的结果是: public class J_Test{ public static void main(String args[ ]){ int i; for(i=0;i<args.length;i++){ System.out.print("args["+i+"]="+args[i]+";"); } } }
简答题 .写出下面程序运行的结果。 public class J_Test{ public static void mb_method(String s,StringBuffer t){ s=s.replace('j','i'); t=t.append("c"); } public static void main(String args[]){ String a=new String("java"); StringBuffer b=new StringBuffer("java"); mb_method(a,b); System.out.println(a+b); } }
简答题 阅读程序,写出正确的运行结果。 public class Test{ public static void main(String args[ ]){ int i , j ; int a[ ] = { 56,12,23,124,100 }; for ( i = 0 ; i < a.length-1; i ++ ) { int k = i; for ( j = i ; j < a.length ; j++ ) if ( a[j]<a[k] ) k = j; int temp =a[i]; a[i] = a[k]; a[k] = temp; } for ( i =0 ; i<a.length; i++ ) System.out.print(a[i]+" "); System.out.println( ); } }
简答题 class Person{ public Person(){ System.out.println("hi!"); } public Person(String s){ this(); System.out.println("I am "+s); } } public class Who extends Person{ public Who(){ this("I am Tony"); } public Who(String s){ super(s); System.out.println("How do you do?"); } public static void main(String args[]){ Who w = new Who("Tom"); } }