- import java.util.HashMap;
- import java.util.Map;
-
- public class CountCharNum {
-
-
-
-
-
- public static void main(String[] args) {
-
- String aString = "yekmaakkccekymbvb";
- int count = 0;
- String singleString = "";
- Map stringMap = new HashMap();
- for (int i = 0; i < aString.length(); i++) {
- singleString = String.valueOf(aString.charAt(i));
- System.out.println(singleString);
- CountCharNum ccn = new CountCharNum();
-
- if (stringMap.get(singleString) == null) {
- count = 0;
- } else {
- count = (Integer)stringMap.get(singleString);
- }
- stringMap.put(singleString, count + 1);
- }
- System.out.println(stringMap);
- }
- }
import java.util.HashMap;import java.util.Map;public class CountCharNum {/*** JAVA编程题:字符串"yekmaakkccekymbvb",求出字符串中有多少种字符,以及每个字符的个数?* */public static void main(String[] args) {String aString = "yekmaakkccekymbvb";int count = 0;String singleString = "";Map stringMap = new HashMap();for (int i = 0; i < aString.length(); i++) {singleString = String.valueOf(aString.charAt(i));System.out.println(singleString);CountCharNum ccn = new CountCharNum();// 第一次出现的字符if (stringMap.get(singleString) == null) { count = 0;} else { count = (Integer)stringMap.get(singleString);}stringMap.put(singleString, count + 1);}System.out.println(stringMap);}}
- public class StringSplit {
-
-
-
-
-
-
-
- String splitString;
- int splitBytes;
-
- public StringSplit(String splitString, int splitBytes) {
- super();
- this.splitString = splitString;
- this.splitBytes = splitBytes;
- System.out.println("The string is : " + splitString
- + ",the splitbytes is :" + splitBytes);
- }
-
- public void splitIt() {
- int num = 0;
- StringBuffer sb = new StringBuffer();
- int i = 0;
- if (splitBytes >= 2) {
- while (num < splitBytes) {
- if (splitString.substring(i, i + 1).matches("[/u4e00-/u9fa5]+")) {
- num += 2;
- } else {
- num++;
- }
- sb.append(splitString.substring(i, i + 1));
- i++;
- }
- System.out.println("final string :" + sb.toString());
- }
- }
-
- public static void main(String[] args) {
- StringSplit ss = new StringSplit("我ABCD妈E爸F", 5);
- ss.splitIt();
- }
- }
public class StringSplit {/*** 编程:编写一个截取字符串的函数, 输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如"我ABC"4,* 应该截为"我AB",输入"我ABC汉DEF"6, 应该输出为"我ABC"而不是"我ABC+汉的半个"。* * @param args*/String splitString;int splitBytes;public StringSplit(String splitString, int splitBytes) {super();this.splitString = splitString;this.splitBytes = splitBytes;System.out.println("The string is : " + splitString+ ",the splitbytes is :" + splitBytes);}public void splitIt() {int num = 0;StringBuffer sb = new StringBuffer();int i = 0;if (splitBytes >= 2) { while (num < splitBytes) {if (splitString.substring(i, i + 1).matches("[/u4e00-/u9fa5]+")) { num += 2;} else { num++;}sb.append(splitString.substring(i, i + 1));i++;}System.out.println("final string :" + sb.toString());}}public static void main(String[] args) {StringSplit ss = new StringSplit("我ABCD妈E爸F", 5);ss.splitIt(); }}
- package com.searchkiller;
-
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
-
- public class AlphaAsc {
-
-
-
-
- public static void main(String[] args) {
-
- String[] aString = {"sbc","fds","des"};
-
- List list = new ArrayList();
- for (int i = 0; i < aString.length; i++) {
- list.add(aString[i]);
- }
- Collections.sort(list);
- System.out.println(list);
- }
-
- }