public class String用法
{
public static void main(String args[])
{
String s1=new String("we are students");
String s2=new String("we are students");
String s3=new String("How are you");
System.out.println("S1字符的长度为:"+s1.length());
int num=0;
if(s1.equals(s2))
System.out.println("S1字符串与S2字符串相等");
if(s1.equals(s3))
System.out.println("S1字符串与S3字符串不相等");
if(s1.startsWith("we are"))
{
System.out.println("S1字符串是以we are开始");
}
if(s1.startsWith("abcde"))
{
System.out.println("S1不是以:abcde开始的");
}
for(int k=0;k<s1.length();k++)
{
if(s1.regionMatches(k, "en", 0, 2))
{
num++;
}
}
System.out.println("S1字符串中含有en的个数为:"+num);
}
if(s1.equals(s3))
System.out.println("S1字符串与S3字符串不相等");
这里 有点问题 如何能叫他输出啊
这里if里面是false 好像他直接就跳出了不执行了 但是我想要他输出后面那个语句 谁能帮我解决这个小问题?谢谢哈。
解决方案 »
- 帮帮忙啊。我都快急死了
- 怎么把JFileChooser里选择的文件传给textfield文本框里
- java中如何用数组来实现栈?
- 如何用io复制一个exe(或类似的文件,如dll)
- 如何由二维数组,变成三维的?
- java.lang.NoClassDefFoundError
- 关于java 版 qq 怎么传输文件的问题
- 怎样把一个.csv文件写如数据库
- JB中用verticalflowlayout,明明把两个panel的位置调好的,一运行位置就自动变了,好像默认位置一样,请问怎样解决?
- 求问,如何这个程序中解决NullPointerException的问题
- JAVA小问题
- 关于java oracle10g 编码方式,入库的问题
System.out.println("S1字符串与S3字符串不相等");
System.out.println("S1字符串与S3字符串不相等");
这是一句相当于
if(s1.equals(s3))
{
System.out.println("S1字符串与S3字符串不相等");
}是这个样子的。
所以当里面条件是false 的时候直接跳出if 不执行
System.out.println("S1字符串与S3字符串不相等");
这么改
if(!s1.equals(s3))
System.out.println("S1字符串与S3字符串不相等");
或者加个else
if(s1.equals(s3))
{
System.out.println("S1字符串与S3字符串相等");
}else System.out.println("S1字符串与S3字符串不相等");