-3

I can't assign a specific char like "X" in part of my input string. For example I want to assign a default char with substring method in specific range of my input string. How can I assign a specific char in specific range of my input string.

Can you help me?

import java.util.*;
public class Algoproject {


    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
         while(true){
        int num=input.nextInt();//number of colums
         if(num!=0)    {  
         String s;
         s=input.next();//enter string without space
        int count=s.length();//string length
         displayMessage(s,num,count);
         }else
             break;    
         }

    }
    public static void displayMessage(String str, int pi,int slength){
      int j=0,i=pi;
      while(pi<=slength){

                System.out.print(str.substring(j,pi )+"\n"); 
                j=pi;
                pi=pi+i;
    }
      System.out.print(str.substring(j,slength )); 
      String in="$";
      //line29
    }}

in line 29 I want a method that give 3 value:

  1. my arbitrary char
  2. first index of my string
  3. last index of my string

and I want to assign that char in this string range

greg-449
  • 109,219
  • 232
  • 102
  • 145

1 Answers1

0

Get the index at which you want to assign your character, suppose it's "x" Then do this

newstring = originalstring.substring(0, x) + your_character + originalstring.substring(x, originalstring.length());
gallickgunner
  • 472
  • 5
  • 20