class Bars_and_Stars { //This method prints all those strings which begins with //S as prefix and i followed by n '|'s and m'*'s //Here we can observe that the two if statements inside else statement //may be written without the else statement. I have written it to increase //understandability public static void PatternS(int n, int m, String S) { if(n==0 && m==0) System.out.println(S); else { if(n!=0) PatternS(n-1,m,S+'|'); if(m!=0) PatternS(n,m-1,S+'*'); } } //This method is written just for better readability and understandability //Otherwise we could have directly called Patterns(n,m,"") from main; public static void Pattern(int n, int m) { PatternS(n,m,""); } public static void main(String args[]) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); System.out.println("The Patterns with "+n+" |'s and "+m+" *s are :"); Pattern(n,m); } }