if语句在满足条件的情况下仍不起作用java

eit6fx6z  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(180)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

16小时前关门了。
改进这个问题
所以我从一个csv文件中获取一些信息,它有游戏和cd的信息,它是一个游戏或cd的信息被存储为“term7”。最后,我希望它打印的游戏或光盘的信息不同,取决于它是哪一个。但是,无论我做什么,if语句从未满足,因此只运行else语句。即使我在if语句之前打印term7的值并显示为“cd”,if仍然不会运行。这是我的密码,谢谢。

package com.company;

import java.io.File;
import java.util.Scanner;

class discSearch {
    private static Scanner keyboard;

    public static void main() {

        System.out.println(" ");
        System.out.println("Enter Name of Record:");

        String filepath = "theFile.csv";
        Scanner ST = new Scanner(System.in);
        String searchTerm = ST.nextLine();

        readRecord(searchTerm, filepath);
    }

    public static void readRecord(String searchTerm, String filePath){
        boolean found = false;
        String term1 = ""; String term2 = ""; String term3 = ""; String term4 = ""; String term5 = ""; String term6 = ""; String term7 = null;

        try{
            keyboard = new Scanner(new File(filePath));
            keyboard.useDelimiter("[,\n]");

            while (keyboard.hasNext() && !found){
                term1 = keyboard.next();
                term2 = keyboard.next();
                term3 = keyboard.next();
                term4 = keyboard.next();
                term5 = keyboard.next();
                term6 = keyboard.next();
                term7 = keyboard.next();

                if(term1.equalsIgnoreCase(searchTerm)){
                    found = true;
                }
            }

            if(found){
                if ("CD".equals(term7)){
                    System.out.println("Title: " + term1 + ",  Artist: " + term2 + ",  Genre: " + term3 + ",  Release Year: " + term4 + ",  Number of Songs: " + term5 + ",  Duration: " + term6 + " Minutes");
                }
                else {
                    System.out.println("Title: " + term1 + ",  Genre: "  + term2 + ",  Release Date: " + term3 + ",  Rating: " + term4 + ",  Platform: " + term5);
                }
            }
            else{
                System.out.println("Not Found");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题