If statement return loop
<p>Just a declaimer:i am a beginner in java.</p>

<p>Write a method named numUnique that takes three integers as parameters and that returns the number of unique integers among the three. For example, the call numUnique(18, 3, 4) should return 3 because the parameters have 3 different values. By contrast, the call numUnique(6, 7, 6) would return 2 because there are only 2 unique numbers among the three parameters: 6 and 7.</p>

<pre><code>public int numUnique(int x,int y,int z){
    if(x==y||y==z){
    }
    return 1;

    else if(x!=y||y!=z){

    }
    return 2;
    
}
</code></pre>

<p>I am very confused about the relationship of if and return.I always put return inside if statement.But i dont understand why does it generate me an error message.if something is fulfil,i return in the loop.Why is it wrong.But on the other hand,the println statement can be put inside for loops.</p>

<p>Another issue,because this question,i tried to attempt using if else too.But my first condition is if and i return it.So after that i placed else if after the first return,it gives me error again.</p>

<p>I will appreciate someone will explain to me and i will alter the codes on my own.Please dont give me the full codes.Thank you.</p>

<p>Edited*
By the way,i read through all the comments and i finally understand it.This is my codes that i work out on my own(:</p>

<pre><code>public static int numUnique(int x, int y, int z) {
    if(x==y &amp;&amp; y==z){
        return 1;
    }else if(x==y &amp;&amp; y!=z || y==z &amp;&amp; z!=x ||  x==z &amp;&amp; y!=z ){
        return 2;
    }
    return 3;
}
</code></pre>
