'运行时错误'在我简单的Java项目中 - 我不知道它来自

时间:2016-06-17 02:15:18

标签: java

我正在ideone.com上创建一个非常简单的小程序,与我的一些朋友分享,但它告诉我有一个'运行时错误'当我输入"再见!"。它本应该回来了!再见!#34;回到我的身边。这是代码:

/* 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是我的代码。

4 个答案:

答案 0 :(得分:1)

我认为你不能把

$('a[data-module^="rooms"]')

你应该省略其他的 请在此处查看如何使用docs using while

答案 1 :(得分:0)

这是编译错误。删除while循环中的else。

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();
    }

答案 2 :(得分:0)

否则仅在IF

之后
if(condition){
//code if condition is true
}
else {
//code if condition is false
} 

删除else {}部分,可以正常工作并做你假装的,也就是在那之后,打印“Bye”

答案 3 :(得分:0)

“虽然”不能有“其他”。 “else”应该出现在“if”

之后