🔒 Closed Help for explanation in java

Status
Not open for further replies.

Donqexote

Enthusiast
Code:
static void higherFever(){
        if(hasFever()==false){
                displayTrue();
            }else{
                displayFalse();
            }
        }
        static boolean hasFever(){
            if(temperature > 36.8){
                return true;
            }else{
                return false;
            }
        }
  
        static void displayTrue(){
            System.out.println("Walang Syang Sakit");
        }
  
        static void displayFalse(){
            System.out.println("My Sakit Sya");
        }
    }
Mga Sir Pa Help Naman Po Medyo naguguluhan lang.

Sample nag input ako ng 45.6
Ang nirereturn nya ay false
Pero kung 45.6 > 36.6
Diba true sya. Pero bakit naging false
Kasi naka asign po ba hasFever ko sa == to false. Gusto ko lang po kasi maklaro.
Salamat po pala and have a good day and gob bless you all.
 
good day, did you try to convert the `temperature` variable to double using the parse method?
because basically, 45.6 is greater than ( > ) 36.6 which is probably true.
Code:
static void higherFever() {
    if(hasFever()==false){
        displayTrue();
    }else{
        displayFalse();
    }
}
the hasFever has a value of true which means hasFever()==false will result in false because true is not equal to false

you can do something like
Code:
static void higherFever() {
    if(hasFever()){
        displayTrue();
    }else{
        displayFalse();
    }
}
or
Code:
static void higherFever() {
    if(hasFever()==true){
        displayTrue();
    }else{
        displayFalse();
    }
}
or
Code:
static void higherFever() {
    if(hasFever()!=false){
        displayTrue();
    }else{
        displayFalse();
    }
}
the first one is a great practice because in the E×ρréššion you're giving the value which is true or false so there is no comparison operator used which means if the boolean E×ρréššion of hasFever is false then it will go to else statement otherwise it will go to true statement.


I hope it helps.
 
good day, did you try to convert the `temperature` variable to double using the parse method?
because basically, 45.6 is greater than ( > ) 36.6 which is probably true.

static void higherFever() {
if(hasFever()==false){
displayTrue();
}else{
displayFalse();
}
}

the hasFever has a value of true which means hasFever()==false will result in false because true is not equal to false

you can do something like

static void higherFever() {
if(hasFever()){
displayTrue();
}else{
displayFalse();
}
}

or

static void higherFever() {
if(hasFever()==true){
displayTrue();
}else{
displayFalse();
}
}


or

static void higherFever() {
if(hasFever()!=false){
displayTrue();
}else{
displayFalse();
}
}

the first one is a great practice because in the E×ρréššion you're giving the value which is true or false so there is no comparison operator used which means if the boolean E×ρréššion of hasFever is false then it will go to else statement otherwise it will go to true statement.


I hope it helps.
Thanks for the explanation sir.
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 329
    Views
  • 3
    Participants
Last reply from:
lockheed18

Online now

Members online
412
Guests online
1,713
Total visitors
2,125

Forum statistics

Threads
2,275,510
Posts
28,963,757
Members
1,232,824
Latest member
almurk
Back
Top