mardi 18 décembre 2018

Why is the main method calling compare() method twice?

Here is the code,

public class Solution {
public static void main(String[] args) {
    compare(5);
}

public static void compare(int a) {
    if(a==5)
        System.out.println("The number is equal to 5");
    if(a<5)
        System.out.println("The number is less than 5");
    else
        System.out.println("The number is greater than 5");
}
}

Here is the output,

The number is equal to 5
The number is greater than 5

I have just called the compare method once, why is it executing twice?

Aucun commentaire:

Enregistrer un commentaire