私は、単語を含むテキストファイルを受け取り、すべての単語を通り抜けて最も多くの単語を出力するプログラムを作成したいという課題に取り組んでいます二重の文字の量。したがって、テキストファイルが2ワード(過去と過去のプログレッシブなど)を持っていた場合、プログレッシブに出力されます。私の問題は、単語の各文字を比較するプログラムを取得しています。具体的には、各単語をその文字に分割する方法を理解できないようです。ここまで私がこれまで持っていたことがあります。配列リストをJavaの個々の文字に分割する方法
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Doubles {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
///Prompts the user to give a file.
System.out.println("Enter the location of your file...");
String location = keyboard.next();
Scanner file = null;
List<String> list = new ArrayList<String>();
///If the the file location is wrong, give an error.
try {
file = new Scanner(new File(location));
} catch (FileNotFoundException e) {
System.out.println("Error: File not found");
System.exit(1);
}
while(file.hasNext()){
String word = file.nextLine();
list.add(word);
}
///System.out.println(list);
keyboard.close();
doublefinder(list);
}
private static void doublefinder(List<String> list) {
///Code to separate and compare letters.
}
}
私はさまざまなアプローチを試みましたが、解決策が見つからないようです。どんな助けでも大歓迎です。
これまでに何を試みましたか? –