路人

导航

<2005年12月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

统计

常用链接

留言簿

随笔档案(39)

相册

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

晕~搞了45分钟

 

import java.lang.*;

public class string {
    
public static void main(String[] agrs) {
        String str1 
= new String("123456789");
        String str2 
= new String("&asdaf");

        
int b = str1.length();
        System.out.println(b);

        
int a = str2.length();

        
for (int i = 0; i < a; i++{
            
char c = str2.charAt(i);
            
if (c == '&'{
                System.out.println(
"有&");
                
break;
            }
 else
                System.out.println(
"没有&");

        }

    }

}

posted on 2005-12-06 11:20 山岗 阅读(274) 评论(2)  编辑 收藏 引用

评论

# re: 晕~搞了45分钟 2005-12-29 15:37 天外流星

如果String str2 = new String("asda&f")呢?  回复  更多评论   

# re: 晕~搞了45分钟 2005-12-29 16:06 山岗

呵呵~严重感谢流行大哥指点~

import java.lang.*;

public class string {
public static void main(String[] agrs) {
String str = new String("asdaf");
int x = 1;
for (int i = 0; i < str.length(); i++) {
char a = str.charAt(i);
if (a == '&') {
x = 2;
break;
}
}
if (x == 2) {
System.out.println("有&");
} else {
System.out.println("没有&");
}
}
}  回复  更多评论   

只有注册用户登录后才能发表评论。