程序没有继续if语句(Java)

时间:2014-08-12 12:01:09

标签: java

所以,这可能看起来像一团糟但是我几个小时前刚刚开始使用Java而且我正在建立一个我脑子里已经有一段时间了。目前,它在最后一部分挂断,询问视频中是否有其他人。知道为什么会这样吗?从变量yn开始在底部。

import java.util.Scanner;

public class Tagger {
  //inputs should include the type of video, who's in it, and what the game is called.
  //Later versions can alter this, including alternate game titles.
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);

    String mod = null;
    String who2 = null;     
    String group = "SmeggCo";

    System.out.println("Welcome to the Actagger! Let's get started.");
    System.out.println("To start, is this a mod spotlight or a Let's Play?");
    String type = input.nextLine();
    System.out.println("Awesome! A " + type + ", eh? Sounds fun!");
    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }

    System.out.println("What game is it?");
    String game = input.nextLine();

    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }
    System.out.println( game + "? I'll have to check that out!");
    if (type == "mod spotlight"){
        System.out.println("What was the mod's name?");
        mod = input.next();
        System.out.println("Huh, I've never heard of" + mod + ".");
    }

    System.out.println("Alright, last question. Who was in this video?");
    String who = input.next();
    System.out.println(who + " is pretty awesome!");
    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }

    System.out.println("Was anyone else in the vid?");
    String yn = input.next();
    if (yn == "Yes"){
        System.out.println("Who?");
        who2 = input.next();            
        System.out.println("So " + who + " and" + who2 + "? Those two are weirdos!");
        String[] tags = new String[5]; //Setup final array of tags. Will add to this later in 2.0
        tags[0] = type;
        tags[1]=game;
        tags[2]=who;
        tags[3]=who2;
        tags[4]=mod;
        tags[5]=group;
        System.out.println("Here's your tags!");
        System.out.println(tags);
        System.out.println("Does that look right? Good!");
    }
    if (yn == "No"){
        String[] tags = new String[5]; //Setup final array of tags. Will add to this later in 2.0
        tags[0] = type;
        tags[1]=game;
        tags[2]=who;
        tags[3]=who2;
        tags[4]=mod;
        tags[5]=group;
        System.out.println("Here's your tags!");
        System.out.println(tags);
        System.out.println("Does that look right? Good!");
    }
}

}

1 个答案:

答案 0 :(得分:1)

你的平等测试是错误的。您应该使用equals()方法,而不是==