我需要創建一個循環鏈接列表,其中節點具有Rider類對象,每個Rider都有一個名稱和一個布爾值。給定一個文本輸入,程序掃描輸入,並增加了車手「線」簡單字符串比較不起作用
public static void main(String[] args) throws FileNotFoundException{
Scanner read = new Scanner(System.in);
CLLOfRiders line= new CLLOfRiders();
System.out.print("Welcome to Project 1." +
"\nWhat is the name of the data file?\n>");
String input=read.nextLine();
File f= new File(input);
Scanner fileread = new Scanner(f).useDelimiter(" - |\n");
while(fileread.hasNext())
{
Rider r=new Rider();
r.name=fileread.next();
System.out.println(r.name);
>>>>> if(fileread.next().equals("Y")) <<<<<
r.changePass(true);
line.addRider(r);
System.out.println(r.speedPassStatus);
}
System.out.println("Finished reading the file.");
line.showWait();
我的問題是,如果由箭頭強調聲明沒有運行過,所以我不能設置車手布爾到正確的值。通過我的賬戶,這似乎是簡單的代碼,應該順利運行?請幫助。對不起,這是我的第一篇文章。
不要修剪()在fileread.next(),看看哪裏的開始和結束大括號如果? – kosa
其只是一行if語句 – user1890605
好的。然後我會確保空格或區分大小寫或兩者都不會導致問題。 – kosa