Q:

find the numbers that give 4 when one number is subtracted from another

i am supposed to find two numbers that give 4 when one number is subtracted from another. the numbers can be 1 to 6. it is supposed to print out:
5  1
6  2
1  5
2  6

i have done this but its not showing me the last two combinations. why?
public class number2
{

    public static void main(String[] args)
    {

        for(int i=1; i<=6; i++)
        {

            for(int j=1; j<=6; j++)
            {
                if(j-i==4)
                {
                    System.out.println(i+ " " +j);
                }
            }
        }
     }
}

A:

Result like following 2 items are not printed.
5  1
6  2
It is becuase, in such situations if(j-i==4) is not satisfied, j-i== -4 here instead of  j-i==4.
Bearing that in mind, if you would like to print the result as you wanted, the value for j-i could be 4 or -4.
You should include these 2 candidate situations.
Change your code with if-condition 
from 
if(j-i==4)

To
if (i - j == 4 || j - i == 4) 

or a simple way is prefered is to use Math.abs method
if(Math.abs(j-i)==4)

