dimanche 21 février 2016

How to use .getClass().getName() with a boolean value in an if--statement [duplicate]

This question already has an answer here:

The code I have is:

    int count = 0;

    Scanner fin = new Scanner(new FileInputStream("planets.txt"));
    while (fin.hasNext()) {
        count ++;
        Double ret = fin.nextDouble();
        System.out.println(ret);
        if (ret.getClass().getName() = String) {
            continue;
        }
    }

The if-statement yields an error because what I did isn't allowed, so how do I say if ret.getClass().getName() == a string, then continue through the loop?

Note, the values in ret are Doubles except at the end of the line in planets.txt, so I want the while loop to continue onto the next line after it encounters the String value in the .txt file

Aucun commentaire:

Enregistrer un commentaire