-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

Dave Newton
  • 158,873
  • 26
  • 254
  • 302

1 Answers1

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
Suhas
  • 31
  • 7
  • 1
    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 – Jens Jul 19 '22 at 12:21