Hi...! i wan to write a program that when i give it a number and a string it replace string with length=number to "1,2...,n" but its replace part doesn't work!
this is the code:

package fasle5;

import java.util.Scanner;

public class Tamrine8 {
    public static void main(String args[]){
        System.out.println("Enter N:");
        Scanner input =new Scanner(System.in);
        int n=input.nextInt();
        System.out.println("Enter String:");
        Scanner input1 =new Scanner(System.in);
        String str=input1.nextLine();
        String s=new String();
        for(int i=1;i<=n;i++)
        {
            s=s+String.valueOf(i);
        }
        String string[]=str.split(" ");
        for(int j=0;j<string.length;j++)
        {
            System.out.println("K"+string[j]);
            if(string[j].length()==n)
            {
                string[j].replace(string[j].substring(j, n), s);
                System.out.println(string[j].substring(j, n));
            }
        }

        for(int k=0;k<string.length;k++)
        {
            System.out.print(string[k]);
        }
    }
}

what is the problem?

I can't understand your description of the requirement! Maybe it would help if you gave a couple of examples of typical inputs and expected results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.