Hii, this code is giving string index out of range exception
import java.net.*; import java.io.*; import javax.swing.*; import java.util.Scanner; public class EraseClient{ public static void main(String args[]){ try { String s = JOptionPane.showInputDialog("Enter the string message"); int len=s.length(); System.out.println("msg size is ="+len); String block=JOptionPane.showInputDialog("enter the block size as a prime number"); int j,result; boolean flag=false; int b=Integer.parseInt(block); while(flag==false) { for (j=2; j< b ;j++ ) { result = b%j; if(result==0) { flag=false; break; } else{flag=true;} } if (flag==false) { String str=JOptionPane.showInputDialog("Reenter the block size as a prime number between 1-100"); b=Integer.parseInt(str); } } System.out.println("Block Size is=" +b); int num= (len/b); String rep=JOptionPane.showInputDialog("enter the replication factor"); int r=Integer.parseInt(rep); System.out.println(" replication factor is ="+ r); int noOfBlocks; if(len%b==0) { noOfBlocks=len/b; } else { noOfBlocks=(len/b)+1; int a=b-(len%b); for(int i=0;i<a;i++) {s=s+"*";} } System.out.println("Message string after adding dummy bits"); System.out.println(s); System.out.println("System will generate total number of blocks=" +noOfBlocks ); int l=0; String[] s3 = new String[100]; for(int i=1;i<=noOfBlocks;i++) { System.out.println("block number"+ i +":"+s.substring(l,l+b)); l=i*b; } for(int k=1;k<=noOfBlocks;k++) { System.out.println("replication of block"+ k + ":"); int value=97; for(int i=1;i<=r;i++) { s3[k] = new String(s.substring(l,l+b)); String strk = Integer.toString(k); String message= strk+ (char)value +" " +s3[k]; value=value+1; System.out.println(message); } } } catch(Exception e) { System.out.println(e); } } }