我的输入与我实际输入的内容不一样?

时间:2014-06-01 04:39:30

标签: java eclipse

我正在启动我的基本计算器,它将以提示询问用户是否要继续开始。但是,每当我输入" Y"在提示符下(使用Eclipse),我总是得到否定回复。每当我输入" N"我得到了同样的东西。任何帮助,将不胜感激。谢谢!

import java.util.Scanner;

public class brain {
public int yes;
public String inputData;
public static void main(String[] args){
    System.out.println("Welcome to Bobert's Calculator. It's pretty restricted, but he's workin' on it.");
    System.out.print("Continue(Y or N): ");

    brain brainObject = new brain();

    brainObject.scannerOutput();

    brainObject.doStuff();

    brainObject.finalPrint();

}
public boolean contYesOrNo(){
    if (yes == 1){
        return true;
    }
    else{
        return false;
    }
}
public void yesTree(){

}
public void evalAns(String ans){
    if(ans == "Y"){
        yes = 1;
    }
    if(ans == "N"){
        yes = 0;
    }
    }
public int test(int num){
    return num;
}
public void finalPrint(){
    if(contYesOrNo()){
        System.out.println("Yup");
    }
    else{
        System.out.println("Nop brah");
        System.out.println(test(yes));
    }
}
public void scannerOutput(){
    @SuppressWarnings("resource")
    Scanner input = new Scanner(System.in);
    // Where the person has to put in Y or N
    inputData = input.nextLine();
}
public void doStuff(){
    evalAns(inputData);
}
}

0 个答案:

没有答案