Why do we use return statement at time 5.23

when I did this without using return the it is giving me
*
**




this star is going very long

and error like this is comming
at BasicsJava.patternByrec.printpattern(patternByrec.java:26)

actual patter is commming with some extra stars and a error

please share your complete code after saving it on ide.codingblocks.com

package BasicsJava; public class patternByrec { public static void main(String[] args) { // TODO Auto-generated method stub printpattern(5, 1, 1); } public static void printpattern(int N, int row ,int col) { if(row >N) return; if(col > row) { System.out.println(); printpattern(N,row+1,1); // return; ---->>> Why we have to use return statement here } System.out.print("*"); printpattern(N, row, col+1); } }

This isnt legible. Go to ide.codingblocks.com paste your code. Press ctrl s. And share the updated url in the search bar here