更多“单选题下列可用作switch(expression)语句参数的是(  )。A String sB Integer iC boolean bD int i”相关问题
  • 第1题:

    下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i,String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String[]args){ print(99,"Int first"); } }

    A.String:String first,int:11

    B.int:11,String:Int first

    C.String:String first,int99

    D.int:99,String:Int first


    正确答案:D
    解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,"Int first"),根据构造方法的参数类型选择调用方法,这里调用的是print(int i,String s)方法,因此输出的是int:99,String:Int first。

  • 第2题:

    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

  • 第3题:

    为了从HTML文件中获取参数,在Applet程序中应该编写的代码是( )。

    A.在start()方法中加入语句String s=getParameter("buttonLabel");

    B.在int()方法中加入语句String s=Parameter("buttonLabel");

    C.在int()方法中加入语句String s=getParameter("BUTTONLABEL");

    D.在start()方法中加入语句String s=getParameter("BUTIONLABEL");


    正确答案:C

  • 第4题:

    已知前序后序求中序的一种

    function ok(s1,s2:string):boolean;

    var i,l:integer; p:boolean;


    正确答案:

     

    begin
    ok:=true;
    l:=length(s1);
    for i:=1 to l do begin
    p:=false;
    for j:=1 to l do
    if s1[i]=s2[j] then p:=true;
    if not p then begin ok:=false;exit;end;
    end;
    end;

    procedure solve(pre,post:string);
    var i:integer;
    begin
    if (pre='''') or (post='''') then exit;
    i:=0;
    repeat
    inc(i);
    until ok(copy(pre,2,i),copy(post,1,i));
    solve(copy(pre,2,i),copy(post,1,i));
    midstr:=midstr+pre[1];
    solve(copy(pre,i+2,length(pre)-i-1),copy(post,i+1,length(post)-i-1));
    end;

  • 第5题:

    在switch(expression)语句中,expression的数据类型不能是( )。 A.doubleB.char

    在switch(expression)语句中,expression的数据类型不能是( )。

    A.double

    B.char

    C.byte

    D.short


    正确答案:A
    A。【解析】本题考查考生对switch(expression)语句的理解。表达式expression只能返回int、byte、short和char,题目中的double是不正确的。同时还要注意,多分支结构中,case子句的值必须是常量,而且所有case子句中的值应是不同的,default子句是任选的。

  • 第6题:

    执行下列程序段之后,变量b的值为______。 public class Test9 { public static void main(String[] args) { int i=12; int j=24; boolean b1=true; boolean b=(j%i== 0)&&(!b1) ||(j/i!=2); System.out.println(b); } }

    A.true

    B.假

    C.1

    D.0


    正确答案:B
    解析:表达式执行次序为:首先做!b1得到false:然后做j%i==0得到true;再做j/i!=2得到false:然后做&&得到false;最后是||得到false。

  • 第7题:

    下列定义语句正确的是:

    A.char c="/n";

    B.int i=12;

    C.float f=2.8;

    D.boolean b=null;


    正确答案:B

  • 第8题:

    在switch(expression)语句中,expression的数据类型不能是()。

    • A、double
    • B、char
    • C、byte
    • D、short

    正确答案:A

  • 第9题:

    在程序中将变量Inta、Bl、St、D分别定义为Integer类型、Boolean类型、String类型和Date类型,下列赋值语句中,正确的是()

    • A、Bl=#True#
    • B、D=#10/05/01#
    • C、Inta="333"+"22"
    • D、St=5+"abc"

    正确答案:A

  • 第10题:

    单选题
    编写JSP小脚本,实现访问该JSP时,在会话对象中保存int型变量i的有效语句是()。
    A

    session.setAttribute(i,”I”)

    B

    session.setParameter(“I”,i)

    C

    session.setAttribute(new Integer(i),”I”)

    D

    session.setAttribute(“I”,new Integer(i))


    正确答案: C
    解析: 暂无解析

  • 第11题:

    单选题
    在switch(expression)语句中,expression的数据类型不能是()。
    A

    double

    B

    char

    C

    byte

    D

    short


    正确答案: D
    解析: 暂无解析

  • 第12题:

    单选题
    在程序中将变量Inta、Bl、St、D分别定义为Integer类型、Boolean类型、String类型和Date类型,下列赋值语句中,正确的是()
    A

    Bl=#True#

    B

    D=#10/05/01#

    C

    Inta=333+22

    D

    St=5+abc


    正确答案: C
    解析: 暂无解析

  • 第13题:

    下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer,int类型和String类型之间的转换。请将程序补充完整。

    程序运行结果如下:

    123

    456

    456

    public class ex7_1{

    public static void main(String[]args) {

    Integer intObj;

    int n;

    String s;

    intObj = new Integer(123);

    n=intObj.__________;

    System.out.printin(Integer.toString(n));

    s=new String("456");

    intObj=Integer._________;

    System.out.println(intObj.__________);

    n=Integer.parseInt(s);

    System.out.println(Integer.toString(n));

    }

    }


    正确答案:intValue() valueOf(s) toString()
    intValue() valueOf(s) toString() 解析:本题主要考查Java类库中对简单数据类型的封装以及对封装类型与基本类型之间的转换。解题关键是熟悉基本数据类型的封装,以及一些常用封装类型的常用转换方法,如Integer类的parseInt()方法等。本题中,第1个空,使用intValue()方法将封装对象intObj转换为基本的数据类型int;第2个空,使用valueOf()方法,将字符串转换为封装对象intObj;第3个空,使用toString()方法,将封装对象intObj转换为字符串打印出来,注意,这里不可以加参数。

  • 第14题:

    下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i, String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String [] args){ print(99,"Int first"); } }

    A.String:Stringfirst,int:11

    B.int:11,String:Int first

    C.String:String first,int:99

    D.int:99,String:int first


    正确答案:D
    解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,“Intfirst”),根据构造方法的参数类型选择调用方法,这里调用的是print(inti,Strings)方法,因此输出的是int:99,String:Intfirst。

  • 第15题:

    阅读以下说明和Java 码,将应填入(n)处的字名写在的对应栏内。

    [说明] 编写一个学生类Student,要求:

    (1) 学生类Student 属性有:

    id: long 型,代表学号

    name: String类对象,代表姓名

    age: int 型,代表年龄

    sex: boolen 型,代表性别(其中:true 表示男,false 表示女)

    phone: String 类对象,代表联系电话

    (2) 学生类Student 的方法有:

    Student (long i,String n,int a,boolean s,String p)

    :有参构造函数,形参表中的参数分别初始化学号、姓名、

    年龄、性别和联系电话。

    int getAge ():获取年龄作为方法的返回值。

    boolean getSex ():获取性别作为方法的返回值。

    String getPhone ():获取联系电话作为方法的返回值。

    public String to String ():以姓名:性别:学号:联系电话的形式作为方法的返

    import java. applet. Applet;

    import java. awt.* ;

    public class Student extends Applet {

    long id;

    String name, phone;

    int age;

    boolean sex;

    Student(long i, String n, int a, boolean s, String p)

    {

    id=i;

    name = n;

    age = a;

    sex= s;

    phone = p;

    {

    public void paint( Graphics g)

    {

    Student x= new Student (5000," xiaoliu" , 89, true, " 8989898" );

    (1);

    (2)

    g. drawstring( x. getPhone( ), 140,140);

    }

    int getAge( )

    { return age; }

    boolean getsex ( )

    { return sex; }

    String getPhone( )

    { return phone; }

    String ToString( )

    {

    (3)

    }

    }


    正确答案:g. drawString(x. ToString( ) 20100) g. drawString(x getAge( ) 80120); retum(“姓名”+name + “学号:” + id + “联系电话:”" +phone) ;
    g. drawString(x. ToString( ) ,20,100) g. drawString(x, getAge( ) ,80,120); retum(“姓名”+name + “学号:” + id + “联系电话:”" +phone) ;

  • 第16题:

    用整数10创建一个Integer类的对象,下列各语句中能完成此功能的是( )。

    A.Integer i=new Integer(10);

    B.Integer i=10;

    C.int i=10;

    D.Integer i=Integer(10);


    正确答案:A
    解析:Integer类是int类型的包装类,其创建和使用方法和一般的类相似,因此答案为A。

  • 第17题:

    3下列程序段运行的结果为( )。 public class Test{ static void print(String s,int i){ System.out.pdntlnC String: "+s+",int:"+i); } static void print(iht i,String s){ System.out.prinflnCint:"+i+",gtring:"+s); } public static void main(String[] args){ print(99,"Int first"); } }

    A.String:String first,int: 11

    B.int: 11,String:Int first

    C.String:String first,int:99

    D. int:99,Stfing:Int first


    正确答案:D

  • 第18题:

    以下程序的编译和运行结果为?class test {static boolean check;public static void main(String args[]) {int i;if(check == true)i=1;elsei=2;if(i= 2、i=i+2;else i = i + 4;System.out.println(i);}}

    A. 3

    B. 4

    C. 5

    D. 6

    E. 语句if(i= 2、编译出错


    正确答案:E

  • 第19题:

    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? () 

    • A、 0
    • B、 3
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第20题:

    下面哪些语句能够正确地生成5个空字符串?()

    • A、String a[]=new String[5];for(int i=0;i<5;a[i++]=“”);
    • B、String a[]={“”,“”,“”,“”,“”};
    • C、String a[5];
    • D、String[5]a;
    • E、String[]a=new String[5];for(int i=0;i<5;a[i++]=null);

    正确答案:A,B

  • 第21题:

    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

  • 第22题:

    单选题
    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.


    正确答案: D
    解析: 暂无解析

  • 第23题:

    单选题
    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()
    A

     0

    B

     3

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


    正确答案: B
    解析: 暂无解析