Q:

I need to achieve an output,but code logic not seems correct

I am beginner level programmer and I am trying to achieve the below mention output, and I code the same in java, but it seems my code is not producing what I expected.
Expected output  
input output
1        1
2        2 
3        3
4        1
5        2
6        3  

Class
public class Testing {

    public static void main(String[] args) {

        for (int i = 1; i < 7; i++) {
          //  System.out.println("the value of i is " + i);
            expectedOutput(i);

        }

    }

    private static void expectedOutput(int i) {

        int localVar = i;
        System.out.println("Input is " + i + " Output is " + localVar);

        if (localVar >= 3) {
            for (int j = 0; j < localVar; j++) {
                localVar = localVar / 2;
                System.out.println("Input is " + i + " Output is " + localVar);
            }
        }
    }
}

Kindly guide me and help me to identify where I committed mistake, thank you so much in advance
output should be
The input is 1 and output is 1
The input is 2 and output is 2
The input is 3 and output is 3
The input is 4 and output is 1
The input is 5 and output is 2
The input is 6 and output is 3

A:

The output is almost input%3, except for numbers that actually are divisible by 3, where it returns 3. You can get this result by subtracting 1 before performing the modulo operator, and then re-adding it:
System.out.printf("Input is %d Output is %d%n", i, (i -1) % 3 + 1);

