public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()A.threeB.otherC.Anexceptionisthrownatruntime.D.Compilationfailsbe

题目

public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()

A.three

B.other

C.Anexceptionisthrownatruntime.

D.Compilationfailsbecauseofanerroronline12.

E.Compilationfailsbecauseofanerroronline13.

F.Compilationfailsbecauseofanerroronline15.


相似考题
参考答案和解析
参考答案:A
更多“public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){ca ”相关问题
  • 第1题:

    最小生成树

    A.Prim算法:

    procedure prim(v0:integer);

    var

    lowcost,closest:array[1..maxn] of integer;

    i,j,k,min:integer;


    正确答案:

     

    begin
    for i:=1 to n do begin
    lowcost[i]:=cost[v0,i];
    closest[i]:=v0;
    end;
    for i:=1 to n-1 do begin
    {寻找离生成树最近的未加入顶点k}
    min:=maxlongint;
    for j:=1 to n do
    if (lowcost[j]<min) and (lowcost[j]<>0) then begin
    min:=lowcost[j];
    k:=j;
    end;
    lowcost[k]:=0; {将顶点k加入生成树}
    {生成树中增加一条新的边k到closest[k]}
    {修正各点的lowcost和closest值}
    for j:=1 to n do
    if cost[k,j]<lwocost[j] then begin
    lowcost[j]:=cost[k,j];
    closest[j]:=k;
    end;
    end;
    end;{prim}

  • 第2题:

    链表的定位函数

    loc(I:integer):pointer; {寻找链表中的第I个结点的指针}

    procedure loc(L:linklist; I:integer):pointer;

    var p:pointer;

    j:integer;


    正确答案:

     

    begin
    p:=L.head; j:=0;
    if (I>=1) and (I<=L.len) then
    while j<I do begin p:=p^.next; inc(j); end;
    loc:=p;
    end;

  • 第3题:

    设有如下程序

    public class test {

    public static void main(String args[]) {

    Integer intObj=Integer.valueOf(args[args.length-1]);

    int i = intObj.intValue();

    if(args.length >1、

    System.out.println(i);

    if(args.length >0)

    System.out.println(i -1、;

    else

    System.out.println(i - 2、;

    }

    }

    运行程序,输入如下命令:

    java test 2

    则输出为:

    A. test

    B. test -1

    C. 0

    D. 1

    E. 2


    正确答案:D

  • 第4题:

    E.堆排序:

    procedure sift(i,m:integer);{调整以i为根的子树成为堆,m为结点总数}

    var k:integer;


    正确答案:

     

    begin
    a[0]:=a[i]; k:=2*i;{在完全二叉树中结点i的左孩子为2*i,右孩子为2*i+1}
    while k<=m do begin
    if (k<m) and (a[k]<a[k+1]) then inc(k);{找出a[k]与a[k+1]中较大值}
    if a[0]<a[k] then begin a[i]:=a[k];i:=k;k:=2*i; end
    else k:=m+1;
    end;
    a[i]:=a[0]; {将根放在合适的位置}
    end;

    procedure heapsort;
    var
    j:integer;
    begin
    for j:=n div 2 downto 1 do sift(j,n);
    for j:=n downto 2 do begin
    swap(a[1],a[j]);
    sift(1,j-1);
    end;
    end;

  • 第5题:

    在下列程序中:

    Program test(input, output);

    var i. j:integer;

    procedure calc(p1, p2: integer);

    beginp2: = p2 * p2 p1: = p1 - p2; p2: = p2 - p1; end {caic}

    begin {main} i: =2;j:=3;

    calc(i,j); write(j);

    end {main}

    当参数传递采用引用方式(Call by reference)时,所得结果j=(6);

    当参数传递采用换名方式(Call by name)时,所得结果,j=(7);

    当参数传递采用赋值方式(Call by value)时,所得结果,j=(8)。

    A.3

    B.6

    C.10

    D.16


    正确答案:D
    解析:一个过程的过程体若包含对其自身的调用,则称此过程是直接递归的。若一个过程的过程体调用某过程,而该过程又调用原过程或经一系列调用后又回到对原过程的调用,则称此原过程是间接递归的。通常实现递归时采用的数据结构是栈,这是因为栈有先进后出的特性,可以保存调用时的“现场”,并在调用结束时恢复“现场”,栈是实现递归的简单途径。对于既可用递归方式求解,也可用循环方式求解的问题,就执行效率和资源而言,显然是循环优于递归,因为递归的开销大。当用户在调用点调用一个过程时,会通过参数传送信息,一个过程的形式参数用来向过程传送信息的标识符,实在参数用来在调用点向被调用过程传送信息。形式参数和实在参数之间的关系通常按照位置来标定,不同程序语言所规定的参数信息传送方式不同。当采用引用方式(Callbyreference)或换名方式(Callbyname)时,在过程中对形式参数的调用本质上是对实在参数单元的引用。先是给形式参数赋初值,而后,在过程中对该形式参数的赋值最终引起调用程序中实在参数值的改变。在本题中形式参数为p1和p2。实在参数初值为i=2和j=3,通过引用方式调用这两个参数,将执行以下计算过程:p1=2p2=3p2:=p2*p2=9p1:=p1-p2=2-3=-7p2:=p2-p1=9-(-7)=16所得结果为j=16。参数传送采用赋值方式时,从调用点向被调用过程传送的是实在参数的值。这一值成为过程中相应位置上形式参数的初值,此后该形式参数在过程中实际是局部变量,其结果无需返回给实在参数。本题中实在参数j=3,在过程中仅起向形式参数F2赋初值的作用。过程中关于p2的运算对j不再起作用,因而过程调用结束后j的值仍为3。

  • 第6题:

    下面的代码用于输出字符数组ch中每个字符出现的次数,应该填入的代码是()public static void main(String[] args) { char[] ch = { 'a', 'c', 'a', 'b', 'c', 'b' }; HashMap map = new HashMap(); for (int i = 0; i < ch.length; i++) { < 填入代码 > } System.out.println(map); }

    A.if (map.contains(ch[i])) { map.put(ch[i], map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }

    B.if (map.contains(ch[i])) { map.put(ch[i], (Integer) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }

    C.if (map.containsKey(ch[i])) { map.put(ch[i], (int) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }

    D.if (map.containsKey(ch[i])) { map.put(ch[i], (Integer) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }


    if (map.containsKey(ch[i])) { map.put(ch[i], (Integer)map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }