2 回答
什么鬼_呀你
TA贡献46条经验 获得超35个赞
第3题的:
public class TEST {
public static void main(String[] args){
String str="aaaaasssssssaaaaaffffhhhhh";
System.out.println("字符串"+str);
char[] c=str.toCharArray();
int a=0;
int s=0;
int f=0;
int h=0;
for(char c1:c){
if(c1=='a'){
a++;
}else if(c1=='s'){
s++;
}else if(c1=='f'){
f++;
}else{
h++;
}
}
System.out.println("a出现"+a+"次!\n"+"s出现"+s+"次!\n"+"f出现"+f+"次!\n"+"h出现"+h+"次!");
}
}
星鸿
TA贡献6条经验 获得超0个赞
public class Test01 {
public static void main(String[] args) {
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
//通过迭代器遍历list
Iterator iter2 = list.iterator();
while(iter2.hasNext()) {
String str = (String) iter2.next();
System.out.println(str);
}
Set set = new HashSet();
set.add("gao1");
set.add("gao2");
set.add("gao3");
//通过迭代器遍历set
Iterator iter = set.iterator();
//for 和 while循环都可以
while(iter.hasNext()) {
String str = (String) iter.next();
System.out.println(str);
}
}
}添加回答
举报
0/150
提交
取消
