题目
String s = new String("xyz");创建了几个String Object?
二者之间有什么区别?
第1题
下面程序执行后,屏幕上显示的应是______。 public class Testl0 { public static void main(String[] args) { char char1[] = {'t', 'e', 's', 't'}; char char2[] = ('t', 'e', 's', 't', '1 }; String s1 = new String(char1); String s2 = new String(char2, 0, 4); System.out.println (si.equal (s2)); } }
A.true
B.假
C.test
D.编译错误
第2题
下列代码段的执行结果是()。 public class Test { public static void main(String args[ ]) { String s1= new String("hello"); String s2= new String("hello"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); } }
A.true false
B.true true
C.false true
D.false false
第3题
下列程序段的输出是()。 public class Test { public static void main (String args[ ]) { String ss1 = new String("hello"); String ss2 = new String("hello"); System. out. println(ssl == ss2); System. out. println (ss1. equals(ss2)); } }
A.true, false
B.true, true
C.false, true
D.false, false
第4题
程序阅读:class Myexception extends Exception
{
Myexception ()
{
super();
}
Myexception(String msg)
{
super(msg);
}
}
public class Test
{
public static void main(String args[])
{
try
{
throw new Myexception(“自定义异常”);
}
catch(Myexception e)
{
System.out.println(e.getMessage());
}
}
}
第5题
请完成下列Java程序:读取自己的源文件并把它压缩成GZIP文件。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import java.io.*;
import java.util.zip.*;
public class exl6 2 {
public static void main{String[] arg) {
ex16_2 obj16_2 = new ex16_2();
obj16_2.doZip("ex16_2.java","ex16_2.gzip")
}
public void doZip(String strIn,String strOut
FileInputStream in;
FileOutputStream out;
GZIPOutputStream gzip;
int nFileLength;
byte[] barray = new byte[10];
try {
in = new FileInputStream(strIn);
out = new FileOutputStream(strOut);
gzip = new GZIPOutputStream(out);
while((nFileLength = in.read(barray, 0 barray.length)) > 0)
_____________________;
______________________;
gzip.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
第6题
给出下面的代码:
public class Person{
static int arr[] =new int[10];
public static void main(String a[]) {
System.out.println(arr[1];)
}
}
以下叙述对的是______。
A.编译时将发生错误 B.编译时正确但是运行时出错
C.输出为0 D.输出为null
第7题
第8题
在C盘当前文件夹下有一个已建立好的顺序文件Alph.txt,文件内容为只含有字母的一个字符串(有双引号界定符)。单击窗体,打开Alph.txt文件,读取字符串并显示在文本框Text1中,然后调用StrSort过程将此字符串按ASCII码的顺序重新排列并显示在文本框Text2,最后将重新排列的字符串存入AlpO.txt文件中(无双引号界定符)。请选择横线处合适的语句 ()。 Private Sub Form_Load()Dim StrIn As String, StrOut As String Open "C:\ Alph.txt" For Input As #1 ______ Close Text1.Text=StrIn ______ Text2.Text=StrOut Open "C:\ AlpO.txt" For Output As #2 ______ CloseEnd SubPrivate Function StrSort(s As String) As String Dim sArr() As String *1, i As Integer, j As Integer, n As Integer Dim t As String*1 n=Len(s) ReDim sArr(n) For i= 1 To n sArr(i) = Mid(s, i, 1) Next i For i=1 To n-1 For j=i+1 To n If sArr(i) > sArr(j) Then t=sArr(i): sArr(i)=sArr(j):sArr(j)=t End If Next j, i For i=1 To n StrSort = StrSort & sArr(i) Next i End Function
A.Input #1, StrIn StrIn Print #2, StrOut
B.Input #1, StrIn StrSort(StrIn) Print #2, StrOut
C.Input #2, StrIn StrSort(StrIn) Print #1, StrOut
D.Print #1, StrIn StrSort(StrIn) Input #2, StrOut
第9题
下列程序的输出结果是()。 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
第10题
下面程序执行后的输出结果为()。 public class fun { public static void main(String args[]) { String greets = " How are you!"; String s = greets.substring(0,3); System.out.println(s); } }
A.How
B.are
C.you
D.how are you!
第11题
在程序的下画线处应填入的选项是()。 public class Test {: public static void main(String args[]){ Test t=new Test; Thread tt=new Thread(t); tt.start; } public void run{ for(int i=0;i<5;i++){ System.out.println("i="+i); } } }
A.implements Runnable
B.extends Thread
C.implements Thread
D.extends Runnable
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!