What's new

Closed Help for explanation in java

Status
Not open for further replies.

Donqexote

Addict
Joined
Nov 29, 2017
Posts
286
Reaction
58
Points
124
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.
 
Last edited by a moderator:
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 expression you're giving the value which is true or false so there is no comparison operator used which means if the boolean expression of hasFever is false then it will go to else statement otherwise it will go to true statement.


I hope it helps.
 
Last edited by a moderator:
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 expression you're giving the value which is true or false so there is no comparison operator used which means if the boolean expression 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.

Similar threads

Back
Top