标签:
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class text { /** * @param args */ public void run(){ // TODO Auto-generated method stub //String a = "Hello World My First Unit Test"; Scanner stdin = new Scanner(System.in); System.out.println("请输入:"); String a = stdin.nextLine(); String[] b = a.split(" "); Map map = new HashMap<String,Integer>(); for(int c = 0;c<b.length;c++) { if(map.containsKey(b[c])) { int d = (Integer)map.get(b[c]); map.put(b[c],d+1); } else { map.put(b[c],1); } } for(Object obj : map.keySet()){ Object value = map.get(obj ); } for(Object obj : map.keySet()) { System.out.println(obj.toString()+"出现了"+map.get(obj)+"次"); } } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class text2 { /** * @param args */ public void run(){ // TODO Auto-generated mrethod stub //String a = "how are you"; Scanner stdin = new Scanner(System.in); System.out.println("请输入:"); String a = stdin.nextLine(); String[] b = a.split(" "); StringBuffer c = new StringBuffer(); for(int d=b.length-1;d>=0;d--) { c.append(b[d]+" "); } System.out.println(c); }
public class main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub text a = new text(); a.run(); text2 b = new text2(); b.run(); } }
标签:
原文地址:http://www.cnblogs.com/westflies/p/5322726.html