社招測(cè)試題(共計(jì)20題,5分/題,總分100分,建議考試時(shí)長(zhǎng):60分鐘,及格線60分)
下面哪個(gè)語(yǔ)句不會(huì)產(chǎn)生編譯錯(cuò)誤?( )
A. float a =2.0;
B. char c =”a”;
C. byte b =25;
D. boolean d=0;下面程序執(zhí)行的結(jié)果是?()
public class Test()
{
public static void main(String[] args)
{
System.out.println(“”+’a’+1);
}
}
A. 98
B. a1
C. 971
D. 197下面程序執(zhí)行的結(jié)果是?()
int i = 100;
while(true)
{
If ( i++ > 100 )
break;
System.out.println(i);
}
A. 100
B. 101
C. 102
D. 103下面程序執(zhí)行的結(jié)果是?()
int a=2;
switch(a)
{
case 1:
a+=1;
break;
case 2:
a+=2;
case 3:
a+=3;
break;
case 4:
a+=4;
break;
default:
a=0;
}
System.out.println(a);
A. 5
B. 6
C. 7
D. 8
下面程序的運(yùn)行結(jié)果是 ( )
int a=3, b=1;
if(a==b)
System.out.println("a="+a);
A. a=1
B. a=3
C. 編譯錯(cuò)誤
D. 正常運(yùn)行但沒(méi)有輸出下面程序的運(yùn)行后,a,b,c的值正確的是:()
int a=1,b=2;
int c=(a+b>3?a++:++b);
A. a=2,b=3
B. a=1,b=3
C. a=1,b=2
D. c=2-
下面程序的運(yùn)行結(jié)果( )
public class Demo
{
public static int fun(int c)
{
return c+=2;
}
public static void main(String[] args)
{
int temp=fun(2); //4
System.out.println(temp);}
}
A. 2
B. 4
C. 6
D. 8
下面程序的運(yùn)行結(jié)果,哪個(gè)是正確的 ()
int b=1;
while(++b<3)
System.out.println("LOOP");
A. 程序?qū)?huì)進(jìn)入死循環(huán)導(dǎo)致無(wú)輸出
B. 輸出一次LOOP
C. 會(huì)輸出多次LOOP
D. 程序中含有編譯錯(cuò)誤下面數(shù)組定義錯(cuò)誤的是()
A. int [] arr ={23,45,65,78,89};
B. int [] arr=new int[10] ;
C. int [] arr=new int[4]{3,4,5,6};
D. int [] arr={‘a(chǎn)’, 23 , 45 , 6};下面程序執(zhí)行的結(jié)果是?( )
int x =1,y=1;
if(x++==2 & ++y==2) //false,x=2 & true,y=2
{
x=7;
}
System.out.println("x="+ x + ", y=" + y);
A. x=1 y=2
B. x=7 y=1
C. x=7 y=2
D. x=2 y=2在Java中,以下程序編譯運(yùn)行后的輸出結(jié)果為( )。
public class Test {
int x, y;
Test(int x, int y) {
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Test pt1, pt2;
pt1 = new Test(3, 3);
pt2 = new Test(4, 4);
System.out.print(pt1.x + pt2.x);
}
}
A. 6
B. 3 4
C. 8
D. 7
請(qǐng)問(wèn)以下代碼的運(yùn)行結(jié)果:()
public class Student{
public Student(){
System.out.println(“a”);
}
public Student(){
System.out.println(“b”);
}
public void show(){
System.out.println(“c”);
}
}
public class Demo{
public static void main(String[] args){
Student stu = new Student();
stu.show();
}
}
A、 a
B、 b
C、 c
D、 編譯出錯(cuò)
- 有如下類定義:
public class Student {
public Student(){
System.out.println("a");
}
public Student(String name){
_________________ ;
System.out.println(name);
}
public static void main(String[] args){
Student stu =____________ ;
}
}
請(qǐng)問(wèn)以下哪些選項(xiàng)依次填入橫線處會(huì)使程序打印字符串“a” ( )
A.this(name);
B.new Student();
C.new Student(“Java”);
D.this();
E.System.out.println(“Java”);
對(duì)字符串”ababcdabcdefg”使用indexOf(‘a(chǎn)’)和lastIndexOf(‘a(chǎn)’),的運(yùn)行結(jié)果是( )
A. 1,1
B. 0,6
C. 0,0
D. 1,6下面程序的運(yùn)行結(jié)果是什么( )
public static void main(String[] args){
String s1 = “abc”;
String s2 = “xyz”;
show(s1,s2);
System.out.println(s1+”-----”+s2);
}
static void show(String s1,String s2){
s1 = s2+s1+”Q”;
s2 = “W”+s1;
}
A. abc-----xyz
B. xyzabcQ-----xyzWabc
C. xyzabcQ---- xyzabcQWabc
D. xyzQ----Wabc將字符串轉(zhuǎn)成字符數(shù)組的方法是( )
A. toString()
B. toCharArray()
C. toUpperCase()
D. toLowerCase()下面程序的運(yùn)行結(jié)果是( )
public static void main(String[] args){
StringBuffer sb = new StringBuffer();
sb.append("qq").append("ww");
show(sb,"ss");
System.out.println(sb.length());
}
static void show(StringBuffer sb,String str){
sb.append(str);
}
A. 4
B. 2
C. 6
D. 0請(qǐng)問(wèn)下面程序的執(zhí)行結(jié)果( )
public class Test{
public static void main(String[] args){
List<String> list = new ArrayList<>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add(10);
for(int i=0;i<list.size;i++){
System.out.println(list.get(i));
}
}
}
A、 [aaa, bbb, ccc, 10]
B、 [10, ccc, bbb, aaa]
C、 編譯錯(cuò)誤
D、 運(yùn)行時(shí)異常-
根據(jù)題目補(bǔ)全代碼。將自定義Student對(duì)象存到ArrayList集合中,要求使用普通for循環(huán)進(jìn)行遍歷( )
public class Student {
private String name;
public Student() {
super();
}
public Student(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class ArrayListTest {
public static void main(String[] args) {
ArrayList<Student> list = new ArrayList<Student>();
list.add(new Student("Jim"));
list.add(new Student("Tom"));
list.add(new Student("LiLei"));for (int i = 0; _____ ; i++) {
Student s = ______;
System.out.println(s.getName());
}
}
A: i < list.size()
B: i<list.length()
C: list.next();
D: list.get(i);
E: list.hasNext(); 關(guān)于StringBuffer和StringBuilder說(shuō)法正確的是( )
A. StringBuffer和StringBuilder的方法不同
B. StringBuffer和StringBuilder都是線程安全的
C. StringBuffer是線程安全的,StringBuilder不是線程安全的
D. StringBuffer不是線程安全的,StringBuilder是線程安全的下面程序運(yùn)行的結(jié)果是( )
String str = “abcdefg”;
str.substring(0,2);
System.out.println(str);
A. ab
B. abc
C. abcdefg
D. 出現(xiàn)下標(biāo)越界異常