私は何が間違っているのか分かりません。どんな助けも素晴らしいだろう!条件付きロジックと文字列操作補助
これは私が探しています出力されます:
Enter text: IDK how that happened. TTYL.
You entered: IDK how that happened. TTYL.
Replaced "IDK" with "I don't know".
Replaced "TTYL" with "talk to you later".
Expanded: I don't know how that happened. talk to you later.
これは私が
debug:
Enter text: IDK how that happened. TTYL.
You entered: IDK how that happened. TTYL.
BUILD SUCCESSFUL (total time: 30 seconds)
package textmsgexpander;
import java.util.Scanner;
/**
*
*/
public class TextMsgExpander {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String BFF = "best friend forever";
String IDK = "I don't know";
String JK = "just kidding";
String TMI = "too much information";
String TTYL = "talk to you later";
String userMSG = "";
//User enters the text and gets output
System.out.println("Enter text: ");
userMSG = scnr.nextLine();
//Program outputs what user entered above
System.out.println("You entered: " + userMSG);
if (userMSG.contains(BFF)){
userMSG = userMSG.replace("BFF", BFF);
System.out.println("Replaced 'BFF' with " + BFF);
{
else if (userMSG.contains(IDK)) {
userMSG = userMSG.replace("IDK", IDK);
System.out.println("Replaced 'IDK' with " + IDK);
}
else if (userMSG.contains(JK)); {
userMSG = userMSG.replace("JK", JK);
System.out.println("Replaced 'JK' with " + JK);
}
else if (userMSG.contains(TMI)); {
userMSG = userMSG.replace("TMI", TMI);
System.out.println("Replaced 'TMI' with " + TMI);
}
else if (userMSG.contains(TTYL)); {
userMSG = userMSG.replace("TTYL", TTYL);
System.out.println("Replaced 'TTYL' with " + TTYL);
else {
System.out.println("Unknown");
}
//Program outputs message with expanded abbreviations
System.out.println("Expanded: " + userMSG);
}
}
複数の省略形を置き換える必要がある場合は、なぜ 'else if'を使用していますか? – fabian