0

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?

2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.