下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }A、 编译报错B、 2C、 1D、 3

题目

下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }

  • A、 编译报错
  • B、 2
  • C、 1
  • D、 3

相似考题
更多“下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }A、 编译报错B、 2C、 1D、 3”相关问题
  • 第1题:

    阅读下面程序

    public class Test3{

    public static void main(String args[]){

    int x=3,y=4,z=5;

    String s= " xyz " ;

    System.out.println(s+x+y+z);

    }

    }

    程序运行的结果是

    A)xyz12

    B)xyz345

    C)xyzxyz

    D)12xyz


    正确答案:B

  • 第2题:

    下面程序的输出结果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }()

    A.lava

    B.java

    C.编译错误

    D.运行时出现异常


    正确答案:B

  • 第3题:

    阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是

    A.args

    B.World One Dream

    C.s

    D.编译时出错


    正确答案:D

  • 第4题:

    下列代码的执行结果是 ( )public class Test2{public static void main(String args[]){int a=4,b=6,c=8;String s="abc";System.out.println(a+b+s+c);}}

    A.ababcc

    B.464688

    C.46abc8

    D.10abc8


    正确答案:D
    解析:该题考查的是int型和String型的混合运算。本题中先算a+b=10,然后再和String型的s相连起来变为字符串10abc,最后在用“+”号把int型的8连起来,结果也是String型的,即10abc8。所以选项D是正确的。

  • 第5题:

    下列程序的输出结果是class Test{public static void main(String args[]){int n=7;n<<=3;n=n&am

    下列程序的输出结果是 class Test{ public static void main(String args[]){ int n=7; n<<=3; n=n&n+1|n+2^n+3; n>>=2; System.out.println(n); } }

    A.0

    B.-1

    C.14

    D.64


    正确答案:C
    解析:本题考查Java中的运算符。首先要清楚程序里面涉及的运算符的含义。“”是按位左移运算符,“&”是按位与运算符,“|”是按位或运算符,“^”是按位异或运算符。题目中整型变量n=7相当于二进制中的111,n=3语句执行后,n值为111000,相当于十进制的56,而语句n=n&n+1|n+2^n+3执行后,n值为57;n>>=2语句执行后,n的值为14,所以选项C正确。

  • 第6题:

    阅读下面程序 public class ConcatTest{ public static void main(String[] args) { String strl = "abc"; String str2 = "ABC"; String str3 = str1.concat(str2); System.out.println(str3); } } 程序的运行结果是:

    A.abe

    B.ABC

    C.abcABC

    D.ABCabc


    正确答案:C
    解析:本题考查字符串的使用。String类提供concat(str)方法,该方法将当前字符串对象与指定str字符串相连。题目程序中生成两个字符串变量str1和str2,并为其赋值,然后生成一个字符串变量str3,该字符串变量的值为表达式str1.concat(str2)的结果。表达式str1.concat(str3)是把字符串str1与字符串str2相连,结果为“abcABC”。
    因此,程序的运行结果是“abcABC”。本题的正确答案是选项C。

  • 第7题:

    下列代码的执行结果是( )。 public class Test { public static void main(String args[ ]) { int a =4,b=6,c=8; String s ="abc"; System.out.println(a+b+s+c); System.out.println(); } }

    A.ababcc

    B.464688

    C.46abc8

    D.10abc8


    正确答案:D
    解析:Java语言对+运算符进行了扩展,使它能够进行字符串的链接。但是一般说来,如果+运算符的第一个操作数是字符串,则Java系统会自动将后续的操作数类型转换成为字符串类型,然后再进行连接:如果+运算符的第一个操作数不是字符串,则运算结果由后续的操作数决定。

  • 第8题:

    执行以下代码会输出什么结果?()   public class Test {    StringgetStr(String s){  return s + “hello”;  }  public static void main(String arg[]) {           Test t= new Test();  System.out.println(t.getStr(“LiLei/n”));     } } 

    • A、 编译报错
    • B、 LiLei    hello
    • C、 LiLeihello
    • D、 无任何输出

    正确答案:B

  • 第9题:

    执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  } 

    • A、 第4行编译报错
    • B、 第5行编译报错
    • C、 编译成功,输出13
    • D、 编译成功,输出14

    正确答案:B

  • 第10题:

    单选题
    执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  }
    A

     第4行编译报错

    B

     第5行编译报错

    C

     编译成功,输出13

    D

     编译成功,输出14


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

  • 第11题:

    单选题
    执行以下代码会输出什么结果?()   public class Test {    StringgetStr(String s){  return s + “hello”;  }  public static void main(String arg[]) {           Test t= new Test();  System.out.println(t.getStr(“LiLei/n”));     } }
    A

     编译报错

    B

     LiLei    hello

    C

     LiLeihello

    D

     无任何输出


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

  • 第12题:

    单选题
    执行以下代码,输出结果的结果是? () public class Test{  public String[] ss = new String[5];    public static void main(String[] args){      System.out.println(ss[1]);  } }
    A

     null

    B

     -1

    C

     编译时出错

    D

     运行时报错


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

  • 第13题:

    下列程序段运行的结果为 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。

  • 第14题:

    下列语句输出结果为( )。 public class test\ { public static void main (String args[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1.equals(s2))); } }

    A.false

    B.true

    C.0

    D.1


    正确答案:A

  • 第15题:

    下列程序的执行结果是

    public class Testee{

    public static void main(String args[ ]){

    int a=4,b=6,c=8;

    String s="abc";

    System.out.println(a+b+s+C) ;

    }

    }

    A.ababcc

    B.464688

    C.46abc8

    D.10abc8


    正确答案:D
    解析:Java对“+”运算符进行了扩展,使它能够进行字符串的连接,如“abc”+“de”得到的字符中是“abcde”,不仅如此,“+”还能够将字符串和其他类型的数据进行连接,其结果是是字符串,例如:"abc"+3得到的字符串“abc3”。但一般来说,如果"+"运算符的第一个操作数是字符串,则Java系统会自动将后续的操作数类型转换成字符串类型,然后再进行连接;如果“+”运算符的第一个操作数不是字符串,则运算结果由后续的操作数决定,例如3+4+5+"abc"的结果是"12abc",而不是"345abc"。

  • 第16题:

    阅读下面程序 public class Test3 { public static void main(String[] args) { int x=3,y=4,z=5; String s="xyz": System.out.println(s+x+y+z); } } 程序运行的结果是

    A.xyz12

    B.xyz345

    C.xyzxyz

    D.12xyz


    正确答案:B
    解析:Java中对+运算符的功能进行了扩展,使其能够进行字符串连接。如"xyz"+"rst"结果为"xyzrst","xyz"+3结果为"xyz3"。如果运算符+的第一个操作数不是字符串,则运算结果由后续的操作数决定,如3+4+5+"xyz"的结果是"12xyz",而不是"345xyz"。

  • 第17题:

    下列代码的执行结果是( )。 public class Test { public static void main (String args[]) { int a=3,b=5,c=8; String s="abc"; System.out.println(a+b+s+c); } }

    A.35abc8

    B.8abc8

    C.16

    D.abc


    正确答案:B
    解析:Java表达式的同级运算符从左到右进行,括号可以改变优先级。+在Java中既是算术的加号,也可以作为字符串的连接符号。本题中a与b先进行算术加运算,得结果为8,由于s的值为String类型,所以数值8与s作连接运算,得结果为字符串“8abc”,最后再与c的值作连接运算,得结果为“8abc8”。

  • 第18题:

    下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }

    A.hello

    B.HELLO

    C.hemmo

    D.HEMMO


    正确答案:A
    解析:String类的replace (char oldChar,char newChar)函数的作用是返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar而生成的。返回的是新字符串,但是原字符串变量的值并未发生改变。因此,输出的是“hello”而不是“hemmo”。如果替换语句换为: s=s.replace('l','m');,则输出“hemmo”。

  • 第19题:

    下面程序段的输出结果为 public class MyClass { public static void main(String args[]) { String s="Hello! How are you?"; System.out.println(s.LastIndexOf("o",16); } }

    A.16

    B.o

    C.u

    D.17


    正确答案:A
    解析:本题考查字符串类中常用成员函数的用法。String类的成员函数lastIndexOf()的原型是:publicintlastIndexOf(Stringstr,intfromIndex)。它用于获得字符串str在给定字符串中从fromIndex位置往回搜索第一次出现的地方。需要注意的是,在字符串中,下标是从0开始的。所以对于字符串s,下标为16的字母正好是o,从这里往前寻找字符串“o”第一次出现的位置,正好就是字符串中。它本身所在的位置。故s.lastIndexOf(“o”,16)返回的结果就是16。

  • 第20题:

    执行以下代码,输出结果的结果是? () public class Test{  public String[] ss = new String[5];    public static void main(String[] args){      System.out.println(ss[1]);  } } 

    • A、 null
    • B、 -1
    • C、 编译时出错
    • D、 运行时报错

    正确答案:C

  • 第21题:

    执行以下代码后,下面哪些描述是正确的() public  class  Student{  private String name = “Jema”;  public void setName(String name){  this.name = name;  }  public String getName(){  return this.name;  }  public static void main(String[] args){  Student s;  System.out.println(s.getName()); } }

    • A、输出null
    • B、第10行编译报错
    • C、第11行编译报错
    • D、输出Jema

    正确答案:C

  • 第22题:

    单选题
    执行以下代码后,下面哪些描述是正确的() public  class  Student{  private String name = “Jema”;  public void setName(String name){  this.name = name;  }  public String getName(){  return this.name;  }  public static void main(String[] args){  Student s;  System.out.println(s.getName()); } }
    A

    输出null

    B

    第10行编译报错

    C

    第11行编译报错

    D

    输出Jema


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

  • 第23题:

    单选题
    下面程序的输出结果是() public class Test{  public static void main(String[] args){    String s = “abc dsf ghi”;  String[] arr = s.split(“/s”);   System.out.println(arr.length);  } }
    A

     编译报错

    B

     2

    C

     1

    D

     3


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