题目内容

当编译运行下列程序时,会出现什么结果_________________。import java.util.*;class Excute6{public static void mA(List list){list.add(Double.toString(8.1));System.out.println(list.get(1));}public static void main(String[] args){ArrayList list =new ArrayList();list.add("Hello One");mA(list);}}

A. Hello One
B. 第3行编译出错
C. 第4行编译出错
D. 第10行编译出错
E. 8.1
F. 执行失败

查看答案
更多问题

当编译运行下列程序时,会出现什么结果_________________。import java.util.*;class Excute7{static int sumUp(List list){int sum=0;for(Iterator iter=list.iterator();iter.hasNext();)sum+=(int)iter.next();return sum;}public static void main(String[] args){ArrayList list =new ArrayList();for(int k=1;k<11;k=k*2+1) list.add(k);System.out.println(sumUp(list));}}

A. 11
B. 15
C. 55
D. 10

当编译运行下列程序时,会出现什么结果______。import java.util.*;interface Book{public String mX();}class ComputerBook implements Book{public String mX(){return "mX()of ComputerBook is been called!";};public String mY(){return "mY()of ComputerBook is been called!";};}class ProgramBook extends ComputerBook{public String mY(){return "mY()of ProgramBook is been called!";};public String mZ(){return "mZ()of ProgramBook is been called!";};}class Excute8{public static void main(String[] args){ArrayList list = new ArrayList();list.add(new ProgramBook());list.add(new ProgramBook());for(int k=0;k

A. 第15行编译出错
B. 第17行编译出错
C. 第18行编译出错
D. mX()of ComputerBook is been called!mY()of ProgramBook is been called!mX()of ComputerBook is been called!mY()of ProgramBook is been called!

如下的程序段输出的结果是__________________import java.util.*;public class Strtest{public static void main(String[] args){String s=new String("we go,to our,compus");StringTokenizer token=new StringTokenizer(s,",");int n=token.countTokens();String array[]=new String[n];for(int i=0;token.hasMoreTokens();i++){array[i]=token.nextToken();System.out.printf("%s,",array[i]);}System.out.printf("\n%d,",n);}}

利用实现接口Comparator的类,重写compare(To1, To2)方法,以此作为TreeMap的排序规则。即按照TreeMap的构造方法public TreeMap(Comparatorcomparator)来创建映像树TreeMap的对象。达到建立有序的映像树结构。存入7名同学的信息(学号、姓名、身高、体重、Java成绩、数据结构成绩,可以有相同的姓名)。要求实现按照姓名+身高+总成绩三个属性由大到小排序(即总成绩相同时按姓名由大到小排序,总成绩和姓名都相同情况下按身高由大到小排序)。import static java.lang.System.*;import java.util.*;//CompareCom实现接口Comparator中的方法compare,//按照Student对象的name,height和score域的从小到大排序class CompareCom implements Comparator{public int compare(String s1, String s2){【代码1】//添加代码,实现compare方法}}class Student{String name=null;int no,height,weight;float score;Student(int n,String name,int h,int w,float sc){no=n;this.name=name;height=h;weight=w;score=sc;}}public class Example7_14xitiX{public static void main(String args[]){Student st1,st2,st3,st4,st5,st6,st7;st1=new Student(1,"zhanying",182,80,95.5f);st2=new Student(2,"wangheng",170,70,98f);st3=new Student(3,"Liuqing",175,60,78f);st4=new Student(4,"zhanying",172,80,85.5f);st5=new Student(5,"wanheng",165,70,92f);st6=new Student(6,"wuquan",162,60,78f);st7=new Student(7,"Lufen",175,60,98.5f);CompareCom compareCom=new CompareCom();//排序树元素与定制的排序方式(按姓名+身高+成绩排序)关联TreeMaptree=new TreeMap(compareCom);tree.put(st1.name+Integer.toString(st1.height)+Float.toString(st1.score),st1);tree.put(st2.name+Integer.toString(st2.height)+Float.toString(st2.score),st2);tree.put(st3.name+Integer.toString(st3.height)+Float.toString(st3.score),st3);tree.put(st4.name+Integer.toString(st4.height)+Float.toString(st4.score),st4);tree.put(st5.name+Integer.toString(st5.height)+Float.toString(st5.score),st5);tree.put(st6.name+Integer.toString(st6.height)+Float.toString(st6.score),st6);tree.put(st7.name+Integer.toString(st7.height)+Float.toString(st7.score),st7);Collection collection=tree.values();Iterator te=collection.iterator();out.printf("\n\n");out.println("按姓名从小到大排序后的结果是: ");out.println(" 姓名身高成绩体重 ");while(te.hasNext()){Student stu=te.next();out.printf("%-15s %5d %10.2f %6d\n",stu.name,stu.height,stu.score,stu.weight);}}}

答案查题题库