Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with the "if" statement

I'm taking a CS course and this code is giving me problems.

         while (statScan.hasNext()){

        currentStat = statScan.next();
        if (currentStat =  h);
        {       
            hStat++;
        }
        System.out.println("" + currentStat);

Look at the "if" statement. Java says "cannot convert string to boolean" and from my understanding boolean is a true/false sorta thing so what Java isn't understanding is how to evaluate and compare the strings. How do I force it to do so?

like image 560
user1869638 Avatar asked Feb 26 '26 01:02

user1869638


1 Answers

the problem is that you assign it instead of ask if it's equal (assign '=', equals '==')
this is the solution for that line: also if it's strings use .equals()

if (currentStat.equals(h))
like image 62
Goran Štuc Avatar answered Feb 27 '26 15:02

Goran Štuc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!