【发布时间】:2013-11-13 00:07:19
【问题描述】:
//程序总是打印写在 if 语句中的行。 //另外,每次我尝试添加else语句时,eclipse都会返回一个错误
import java.util.Scanner;
import java.util.Arrays;
public class Practice {
public static void main(String[] args)
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of artists you would like to search: ");
int number = input.nextInt();
String junk = input.nextLine();
String []artist = new String[number];
for(int i=0; i < number ; i++)
{
artist[i]= input.nextLine();
}
System.out.println("Here is the list of artists you searched for: " + Arrays.toString(artist) + ". Is this correct?");
String check = input.nextLine();
if((check.equalsIgnoreCase("yes") || check.equalsIgnoreCase("y")) == false); //this continually returns both print statements in and out of the if statement even if I input something other than yes or y and I have no idea why
{
System.out.println("Cool! Enjoy your search!"); //this always prints no matter what
}
System.out.println("Please try again! Sorry for the inconvenience!"); //won't let me add an else statement
【问题讨论】:
-
天啊。我花了过去一个小时试图弄清楚这件事,罪魁祸首是一个分号。 (以及我缺乏勤奋)非常感谢!
标签: java string if-statement boolean