日期:2014-05-20 浏览次数:20632 次
import javax.swing.JOptionPane;
public class Work8_4 {
public static void main(String[] args) {
String s = JOptionPane.showInputDialog("请输入");
System.out.println(count(s));
}
public static int count(String str,char a){
char[] chars=s.toCharArray();
java.util.Arrays.sort(chars);
String c=new String(chars);
return c;
}
}
public static void main(String[] args) {
String s = JOptionPane.showInputDialog("请输入");
System.out.println(count(s, 'a'));
}
public static int count(String str, char a) {
char[] chars = str.toCharArray();
int r = 0;
for (char c : chars) {
if (c == a) {
++r;
}
}
return r;
}