Divide a string in N equal parts | if ( start < str . length ( ) ) System . out . println ( ) ; to ignore final new line ; Driver code
import java . util . * ; class GFG { static void divide ( String str , int n ) { if ( str . length ( ) % n != 0 ) { System . out . print ( " Invalid ▁ Input : ▁ String ▁ size " ) ; System . out . print ( " ▁ is ▁ not ▁ divisible ▁ by ▁ n " ) ; return ; } int parts = str . length ( ) / n ; int start = 0 ; int t = parts ; while ( start < str . length ( ) ) { String temp = new String ( str ) ; System . out . print ( temp . substring ( start , parts ) + "NEW_LINE"); start = parts ; parts += t ; } } public static void main ( String [ ] args ) { String str = " a _ simple _ divide _ String _ quest " ; divide ( str , 4 ) ; } }