问:这个java代码有什么问题吗?

时间:2014-11-27 15:57:01

标签: java syntax

package firstproject;
import java.util.Scanner;

public class walkthrough {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();       
        System.out.println("Welcome home!");
        System.out.println("Would you like to go in?");
        String door = a;
        if(a.equals(door));
        System.out.println("Your are now in the house what now?");
    }        
}

4 个答案:

答案 0 :(得分:1)

此:

if(a.equals(door));
    System.out.println("Your are now in the house what now?");

是:

if(a.equals(door)) { }
System.out.println("Your are now in the house what now?");

无论if条件中表达式的值如何,都将执行print语句。

删除;条件后的多余if

另请遵循惯例并将您的班级重命名为大写字母。

答案 1 :(得分:0)

if语句后的分号。改变;在{

答案 2 :(得分:0)

if(a.equals(door)); // semicolon - statement
        System.out.println("Your are now in the house what now?");

这意味着执行System.out.println("Your are now in the house what now?");而不管if语句。

答案 3 :(得分:-1)

类名应以Java中的大写字母开头:walkthrough - > Walkthrough