Print Consecutive numbers by comparing two parameters input 3,5 output should be 3,4,5

input 5,3 output should be 5,4,3

And the code

public static void test(int a, int b) {
        if(a&gt;b) {
            for (int i = a; i &gt;= b; i--) {
                System.out.print(i + "\t");
            }
        }else if(a&lt;b) {
            for (int i = a; i &lt;= b; i++) {
                System.out.print(i + "\t");
            }
        }
    }


It works but looks a little messy. Is it possible to do without if else thing? Only one loop.
The function name is weird.  What is it testing?  A more appropriate name might be printInclusiveRange(…, …).

Since the bounds are inclusive, I would expect that for input 3,3, the output should be 3.  Yet you output nothing.

I would also expect the output not to end with a Tab character.

Here's one solution that corrects those two problems, and also combines the loops:

public static void printInclusiveRange(int a, int b) {
    System.out.print(a);
    if (a != b) {
        int i = a;
        int step = (a &lt; b) ? +1 : -1;
        do {
            i += step;
            System.out.print("\t" + i);
        } while (i != b);
    }
    System.out.println();  // Perhaps you want a newline here?
}