求指定字符的出现次数时出了一些有关问题
求指定字符的出现次数时出了一些问题
大一新生不甚求解叩谢各位
------最佳解决方案--------------------
------其他解决方案--------------------
你的count方法要求有两个变量传进去,但是你调用方法的时候,只传进去一个啊
------其他解决方案--------------------
具体应该怎么改
------其他解决方案--------------------
------其他解决方案--------------------
这个不是你想要的效果么?
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;
}
------其他解决方案--------------------
你的count方法要求有两个变量传进去,但是你调用方法的时候,只传进去一个啊
------其他解决方案--------------------
具体应该怎么改
------其他解决方案--------------------
------其他解决方案--------------------
这个不是你想要的效果么?