How to "attach" String var to int var

324 views Asked by At

I'm trying to keep track of a String variables corresponding int values (which don't change). So when the program sorts the array of integers I want the String to be sorted in the same way. I don't have any code for this at the moment because I'm clueless where to begin, any help will be appreciated.

1

There are 1 answers

0
user3059141 On
    String p="caegbdfih";
    int[] a = {3,1,5,7,2,4,6,9,8};
    String p1 = "";
    char[] c = p.toCharArray();
    int i,j,temp;
    char ctemp;
    for(i=0;i<a.length;i++)
    {
        for(j=0;j<a.length;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
                ctemp=c[i];
                c[i]=c[j];
                c[j]=ctemp;
            }
        }
    }
    for(i=0;i<a.length;i++)
    {
        System.out.print(a[i]);
    }
    System.out.println();
    for(i=0;i<a.length;i++)
    {
       System.out.print(c[i]);
    }