LAPTOP-8KA88UT5_20200826-陈浩
问题
1、今天讲的听的有点懵
2、求一行字符中空格的个数
解决:
空格的ASCII码值是32
System.out.println("请输入一行字符:");
String ch = input.nextLine();
int count_kong=0;
for (int i = 0; i < ch.length(); i++) {
char single = ch.charAt(i);
if(single==32) {
count_kong++;
}
}
System.out.println("空格的个数为:"+count_kong+"个");
3、已解决
String s="abc";
String x="abc";
System.out.println(s==x);//true
String ss = new String("asd");
String aa = new String("asd");
System.out.println(ss.equals(aa));//true
吐槽
无
点赞