-2

I need to replace a word in array Eg: if string[]a = [1,2,3] as input string []b= [a,b,c]

If I get the input in array has 3,2,1 it should print c,b,a. Can anyone please help me

4
  • 1
    So is no code writing service. Try to solve your task and come back if you have a specific problem Commented Jul 19, 2022 at 9:12
  • Hi Jen's , I tried but I am failing in every attempt. Commented Jul 19, 2022 at 9:30
  • Than show us your attempt so that we can help you fix the issue Commented Jul 19, 2022 at 9:35
  • Maybe this helops you stackoverflow.com/questions/5328996/java-change-int-to-ascii Commented Jul 19, 2022 at 9:38

1 Answer 1

0

Use map like this to get that

 private static void getArray(int[] num) {
    TreeMap<Integer, Character> tMap = new TreeMap<>();
    char c = 0;
    int i = 1;
    for (c = 'a'; c <= 'z'; c++) {
        tMap.put(i, c);
        i++;
    }
    System.out.println("Map = " + tMap);
    for (int k = 0; k < num.length; k++) {
        System.out.println("Map by key = " + tMap.get(num[k]));
    }
}

This will give following result:

input : int[] num  = {4,5,6};
output : Map = {1=a, 2=b, 3=c, 4=d, 5=e, 6=f, 7=g, 8=h, 9=i, 10=j, 11=k, 12=l, 13=m, 14=n, 15=o, 16=p, 17=q, 18=r, 19=s, 20=t, 21=u, 22=v, 23=w, 24=x, 25=y, 26=z}
Map by key = d
Map by key = e
Map by key = f
Sign up to request clarification or add additional context in comments.

1 Comment

Because you should not write the code for OP, if there is no effort to see that OP has tried to solve his problem. SO is not a code writing service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.