javaSE学习总结(9)java常用类

章节练习题及面试题

判断输出结果
public void testString(){
String str1 = “中国”;
String str2 = “中国”;
String str3 = new String(“中国”);
System.out.println(str1 == str2);//true
System.out.println(str1 == str3);//false
System.out.println(str1.equals(str3));//true
str1 = “中国atguigu.com”;
String str4 = “atguigu.com”;
String str5 = “中国” + “atguigu.com”;
System.out.println(str1 == str5);//true

String str6 = (str2 + str4).intern();
System.out.println(str1 == str6);//false  ---->true

}

String s = new String(“xyz”);创建了几个String Object
答:两个,一个字符对象,一个字符对象引用对象

Math.round(11.5)等于多少? Math.round(-11.5)等于多少
答: Math.round(11.5)12;Math.round(-11.5)-11;round方法返回与参数最接近的长整数,参数加1/2后求其floor

是否可以继承String类
答:String类是final类故不可以继承

String与StringBuffer的区别
答:String的长度是不可变的,StringBuffer的长度是可变的。如果你对字符串中的内容经常进行操作,特别是内容要修改时,那么使用StringBuffer,如果最后需要String,那么使用StringBuffer的toString()方法

一、判断题
1.用运算符“”比较字符串对象时,只要两个字符串包含的是同一个值,结果便为 true。()
2.String 类字符串在创建后可以被修改。()
3.方法 replace (String srt1, String srt2)将当前字符串中所有 srt1 子串换成 srt2子串。
4.方法compareTo在所比较的字符串相等时返回 0。()
5.方法IndexOf((char ch,-1)返回字符ch在字符串中最后一次出现的位置。()
6.方法startsWith()判断当前字符串的前缀是否和指定的字符串一致。()
二、选择题
1.下面哪个选项正确地声明了一个字符串数组:
A char str[]
B char str[][]
C String str[]
D String str[10]
2. 请看下面的程序段:
public class class1{
public static void main(String a[]) {
int x [] = new int[8];
System .out .println(x [1]);
} }
当编译和执行这段代码时会出现:
A 有一个编译错误为“possible reference before assignment”
B 有一个编译错误为“illegal array declaration syntax”
C 有异常出现为“Null Pointer Exception”
D 正确执行并且输出 0
3.已知 String 对象 s=“abcdefg”,则s.substring(2, 5)的返回值为____。
A “bcde”
B “cde”
C “cdef”
D “def”
4.请看下面的代码 String s = “people”; String t = “people”; String c[ ] = {“p”,”e”,”o”,”p”,”l” ,”e”};
下面哪一选项的语句返回值为真:
A s .equals(t);
B t .equals©;
C s
t;
D t .equals(new String(“people”));
E t==c;
5.已知 s 为一个 String 对象,s=“abcdefg”,则s.charAt(1)的返回值为____。
A a
B b
C f
D g
6.请看下面的代码 String s = “good”; 下面选项语句书写正确的是:
A s += “student”;
B char c = s[1];
C intlen = s .length;
D String t = s.toLowerCase( );
7.正确创建一个含有 5 个元素的字符串数组的选项是:
A String s[ ] = new String[5]; for(int i=0;i<5;s[i++]=“”);
B String s[ ]={“”, “”, “”, “”, “”};
C String s[5];
D String [5]s;
8.请看下面的代码
public class class1{
String str = new String(“Girl”);
charch[ ]={‘d’,‘b’,‘c’};
public static void main(String args[ ]){
class1 x=new class1( );
x.change(x.str,x.ch);
System .out .println(x.str +" and "+x.ch[0]+x.ch[1]+x.ch[2]);
}
public void change(String str,charch[ ]){
str=“Boy”; ch[0]=‘a’;
} }
该程序的输出结果是:
A Boy and dbc
B Boy and abc
C Girl and dbc
D Girl and abc

Math.round(11.5)和Math.round(-11.5)的值是多少?
Math.round(11.5):12
Math.round(-11.5):-11

String str = new String(“hello”);创建了哪些对象?
字符串常量池中有一个对象,堆中有一个字符串对象。

如何将String类型转化Number类型?举例说明String str = “123”;
答任意一个都对:
Integer num1 = new Integer(str);

int num2 = Integer.parseInt(str);

Integer num3 = Integer.valueOf(str);

三、填空题

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值