私はideone.comの非常に簡単なプログラムを使って私の友人と分かち合っていますが、 「Bye!」と入力すると「ランタイムエラー」です。それは "さようなら"を返すはずでした。私に戻って。コードは次のとおりです。私の単純なJavaプロジェクトで「ランタイムエラー」 - どこから来ているのか分かりません
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
System.out.println("Hi!");
String nxt = scan.nextLine();
while (nxt!="Bye" || nxt!= "Bye!" || nxt!="bye" || nxt!="bye!"){
reply("How are you?", "I'm fine, thanks.", nxt);
reply("What is your favorite color?", "Light green! It is so pretty!", nxt);
reply("What do you like to eat?", "Oh, I don't. Computers don't eat.", nxt);
reply("Do you like me?", "Yes, but you're way too inquisitive!", nxt);
reply("What's your favorite memory?", "Um...Something about my CPU having an extremely - okay...I don't think....Um...", nxt);
reply("Where did you learn how to talk?", "This program.", nxt);
reply("So...Are you alive?", "No. I don't regulate my body temperature. \n !!!COMPUTER OVERHEATED!!!", nxt);
reply("Do you know any jokes?", "Why don't you program some...?", nxt);
nxt = scan.nextLine();
}
System.out.println("Bye!");
}
public static void reply (String input, String output, String compare){
boolean lia = compare.contains(input);
if(lia == true){
System.out.println(output);
}
}
}
誰でも見たい場合は、hereが私のコードです。
これは実行時エラーではありません。 IDEONEはコンパイルエラー*であるため、 "コンパイル情報"にエラーを表示します。これは、 'else'節に' if'文がないことが原因です。 **** Main.java:25:エラー: 'else' if 'なし' *** – Andreas
実際のIDEをダウンロードするだけで、本当に良い無料のものがいくつかあります。 IntelliJのように –
Pythonの背景から来ていますか? Javaはしばらくの間にelse文を使用しません –