我是java初学者,问各大侠一个小小的问题
package bytecode;
import java.util.*;
public class string {//private Object size;/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Set e=new HashSet();
for(String q:args){
if(!e.add(q)){
e.size();
q.;}
}
System.out.println(e.size());
}}
这个代码要实现的功能是:输入字符串并输出字符串中涉及那些字符的种类
谁能补充完整啊!!
package bytecode;
import java.util.*;
public class string {//private Object size;/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Set e=new HashSet();
for(String q:args){
if(!e.add(q)){
e.size();
q.;}
}
System.out.println(e.size());
}}
这个代码要实现的功能是:输入字符串并输出字符串中涉及那些字符的种类
谁能补充完整啊!!
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Input Your String!");
String str = sc.nextLine();
Map<Character, Integer> map = countLetters(str);
System.out.println("total kinds: " + map.size());
for (Map.Entry<Character, Integer> entry : map.entrySet()) { //增强的for循环
System.out.printf("letter %c: %d\n", entry.getKey(), entry.getValue());
}
} static Map<Character, Integer> countLetters(String s) {
if (s == null) {
return null;
}
Map<Character, Integer> map = new HashMap<Character, Integer>();
char c;
Integer oldValue;
int newValue;
for (int i = 0; i < s.length(); ++i) {
c = s.charAt(i);
oldValue = map.get(c);
newValue = (oldValue == null) ? 1 : oldValue.intValue() + 1;
map.put(c, newValue);
}
return map;
}
}