我的Java HW将使用一些股票市场数据,读/写文件。我正在尝试将此选项(下方)放入代码中,出于某种原因,当我输入Y
时,它不会进入for-loop
。我无法弄清楚为什么。当我输入Y
时,它直接进入下一个代码块并开始将数据打印到屏幕上(正如它应该做的那样),没有任何以下输出/输入。
System.out.println("Would you like to add items to the StockMarket data? (Y or N)");
Scanner input_check = new Scanner(System.in);
if(input_check.next() =="Y"){
//Scanner inp = new Scanner(System.in);
System.out.println("Enter name of stock (all caps): ");
//String input = inp.next();
names.add(input_check.next());
System.out.println("Enter date (MM/DD/YEAR) of stock data: ");
dates.add(input_check.next());
System.out.println("Enter the opening price: ");
opening.add(input_check.next());
System.out.println("Enter the closing price: ");
closing.add(input_check.next());
System.out.println("Enter the highest price: ");
highest.add(input_check.next());
System.out.println("Enter the lowest price: ");
lowest.add(input_check.next());
}