There isn't a shortcut like what you've posted...
And what do you mean "In a single line"?
If in one line of code... see Mureinik's answer
If print "_" in one line:
Instead:
Print 1 to 10 without any loop in java
System.out.print("_");
System.out.print("_");
System.out.print("_");
System.out.print("_");
System.out.print("_");
Or
public void recursiveMe(int n) {
if(n <= 5) {// 5 is the max limit
System.out.print("_");//print n
recursiveMe(n+1);//call recursiveMe with n=n+1
}
}
recursiveMe(1); // call the function with 1.