『新手』检查一下句子的英文字..
本帖最后由 ken0910 于 2013-12-06 21:50 编辑检查一下句子的英文字..
我现在学习JAVA中,所以有一些问题不慬。
input: "June, July and August"
output: 4 u, 2 J, 2 n
要检查一下句子中,出现最多次數的3個英文字..
我只慬写出
import java.util.Scanner;
public class Task_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Input the word: " );
word = input.next();
不知道应该怎样用array去写:dizzy:
希望大哥们可以教教我:)
说实话,我没有看懂你的需求。
要检查一下句子中,头三个最多出现的英文字.. 回复 2# ddd010
謝謝師兄的回覆:)
意思是output要出现最多次數的3個英文字..:)
import javax.swing.JOptionPane;
public class test {
public static void main(String[] args) {
String words = JOptionPane.showInputDialog(null,"Write a sentence." );
String lower = words.toLowerCase();
char[] ch = lower.toCharArray();
int[] freq = new int;
for(int i = 0; i< ch.length;i++)
{
if(ch <= 122)
{
if(ch >= 97)
{
freq[(ch-97)]++;
}
}
}
System.out.println("Total chars " + ch.length);
for(int i = 0; i < 26; i++)
{
if(freq != 0)
System.out.println(freq + "\t" + ((char)(i+97)));
}
}
}
我只計算出小草的英文,不懂計算出大草的.
還有選出3個出現最多次的字母...
页:
[1]