Java StringBuilder
Enter the number to show them in sequence of max 5 number in row.
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
for example print below number:-
1 2 3 4 5
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
Post a Comment