网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
单选题
下列可用作switch(expression)语句参数的是( )。
A
String s
B
Integer i
C
boolean b
D
int i
参考答案
参考解析
解析:
表达式expression最终值的类型必须是int型或者是能自动转换成int型的类型,如short、byte、char。否则,必须进行强制类型转换。case子句中的值value必须是常量,而且所有case子句中的值是不同的。A项,是一个字符串常量;B项,Integer是一个类;C项,是一个布尔型变量。
表达式expression最终值的类型必须是int型或者是能自动转换成int型的类型,如short、byte、char。否则,必须进行强制类型转换。case子句中的值value必须是常量,而且所有case子句中的值是不同的。A项,是一个字符串常量;B项,Integer是一个类;C项,是一个布尔型变量。
更多 “单选题下列可用作switch(expression)语句参数的是( )。A String sB Integer iC boolean bD int i” 相关考题
考题
执行下列程序段之后,输出的结果为______。public class exl0{public static void main(String[] args){int i=3;int j=7;int k=8;boolean b=j>i∧k!=i;System.out.println(b);}}
考题
下列程序段运行的结果为 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:11B.int:11,String:Int firstC.String:String first,int99D.int:99,String:Int first
考题
下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer,int类型和String类型之间的转换。请将程序补充完整。程序运行结果如下:123456456public 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));}}
考题
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.Compilationfailsbecauseofanerroronline12.E.Compilationfailsbecauseofanerroronline13.F.Compilationfailsbecauseofanerroronline15.
考题
下列程序段运行的结果为 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:11B.int:11,String:Int firstC.String:String first,int:99D.int:99,String:int first
考题
为了从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");
考题
阅读以下说明和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)}}
考题
用整数10创建一个Integer类的对象,下列各语句中能完成此功能的是( )。A.Integer i=new Integer(10);B.Integer i=10;C.int i=10;D.Integer i=Integer(10);
考题
在switch(expression)语句中,expression的数据类型不能是( )。 A.doubleB.char
在switch(expression)语句中,expression的数据类型不能是( )。A.doubleB.charC.byteD.short
考题
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: 11B.int: 11,String:Int firstC.String:String first,int:99D. int:99,Stfing:Int first
考题
执行下列程序段之后,变量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.trueB.假C.1D.0
考题
以下程序的编译和运行结果为?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. 3B. 4C. 5D. 6E. 语句if(i= 2、编译出错
考题
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、 0B、 3C、 Compilation fails.D、 An exception is thrown at runtime.
考题
下面哪些语句能够正确地生成5个空字符串?()A、String a[]=new String[5];for(int i=0;i5;a[i++]=“”);B、String a[]={“”,“”,“”,“”,“”};C、String a[5];D、String[5]a;E、String[]a=new String[5];for(int i=0;i5;a[i++]=null);
考题
在程序中将变量Inta、Bl、St、D分别定义为Integer类型、Boolean类型、String类型和Date类型,下列赋值语句中,正确的是()A、Bl=#True#B、D=#10/05/01#C、Inta="333"+"22"D、St=5+"abc"
考题
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、Compilationfailsbecauseofanerroronline12.E、Compilationfailsbecauseofanerroronline13.F、Compilationfailsbecauseofanerroronline15.
考题
单选题编写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))
考题
单选题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
Compilationfailsbecauseofanerroronline12.E
Compilationfailsbecauseofanerroronline13.F
Compilationfailsbecauseofanerroronline15.
考题
单选题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
0B
3C
Compilation fails.D
An exception is thrown at runtime.
考题
单选题在程序中将变量Inta、Bl、St、D分别定义为Integer类型、Boolean类型、String类型和Date类型,下列赋值语句中,正确的是()A
Bl=#True#B
D=#10/05/01#C
Inta=333+22D
St=5+abc
热门标签
最新试卷