当编译运行下列程序时,会出现什么结果______。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(Comparator super K>comparator)来创建映像树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);}}}
自动售货机程序模板 请填写相应代码、编译、运行模板给出的代码,然后完成试验后的练习。MachineSell.javaimport java.util.Scanner;public class MachineSell {public static void main(String args[]){int money;int drinkKind;System.out.printf("投入金额:2或3元(回车确认):");Scanner reader=new Scanner(System.in);money=reader.nextInt();【代码1】//判定投币的面System.out.printf("选择净净矿泉水(1),甜甜矿泉水(2)和美美矿泉水(3)之一:\n");System.out.printf("输入1,2或3:");drinkKind=reader.nextInt();//【代码2】//选择饮料case 1 : System.out.printf("得到净净矿泉水\n");break;case 2 : System.out.printf("得到甜甜矿泉水\n");break;case 3 : System.out.printf("得到美美矿泉水\n");break;default: System.out.printf("选择错误");}}else if(money==3) {System.out.printf("选择爽口可乐(1),清凉雪碧(2),和雪山果汁(3)之一:\n");System.out.printf("输入1,2或3:");drinkKind=reader.nextInt();switch(drinkKind) {case 1 : System.out.printf("得到爽口可乐\n");break;case 2 : System.out.printf("得到清凉雪碧\n");break;case 3 : System.out.printf("得到雪山果汁\n");break;default: System.out.printf("选择错误");}}else {System.out.printf("输入的钱币不符合要求");}}}