3

とにかく StringBuilder の toUpperCase のようなものを使用する方法があるかどうか疑問に思っていましたか? 以下は私のコードです。フレーズのユーザー入力を取得して頭字語に変換しようとしています。誰かが StringBuilder を提案して助けてくれましたが、頭字語を大文字にする方法があるかどうかわかりません。どんな助けでも大歓迎です。

public class ThreeLetterAcronym {

public static void main(String[] args) {
    String threeWords;
    int count = 0;
    int MAX = 3;
    char c;
    //create stringbuilder
    StringBuilder acronym = new StringBuilder();

    Scanner scan = new Scanner(System.in);

    //get user input for phrase
    System.out.println("Enter your three words: ");
    threeWords = scan.nextLine();

    //create an array to split phrase into seperate words.
    String[] threeWordsArray = threeWords.split(" ");

    //loop through user input and grab first char of each word.
    for(String word : threeWordsArray) {
        if(count < MAX) {
            acronym.append(word.substring(0, 1));
            ++count;

        }//end if
    }//end for  

    System.out.println("The acronym of the three words you entered is: " + acronym);
    }//end main
}//end class
4

2 に答える 2