Java StringBuilder

Enter the number to show them in sequence of max 5 number in row. 
   for example print below number:-
    1 2 3 4 5         

    6 7 8 9 10       

    11 12              


  Here is Java code for to do this:-


     import java.util.*;
       class printNoSquesce{
 public static void main(String args[]){
int i=12;

StringBuilder sb=new StringBuilder();

for(int j=1;j<=i;j++){
if(j%5==0 ){
sb.append(j);
sb.append(" ");
sb.append("\n");
System.out.println();
}else{
sb.append(j);
sb.append(" ");

}
}
System.out.print(sb);

      }
     }

Below in output Of programme


Comments

Popular posts from this blog

MVVM Kotlin setup Android

How to give run time permission in android

Take screen shot in android programmatic (Android Studio)