java - Need to print the values of an array that is parallel to one I sorted using bubble sort -
i have school project supposed make car rental application in bluej using java. 1 part, have 2 arrays, 1 price , 1 name of car. have print name of car in descending order of price. have managed sort price array in descending order using bubble sort not able figure out how print name of car when sorted price array. please help.
string carmodel[] = {"a", "b", "c"}; //names of cars int costperday[] = {100, 75, 250}; //rental cost per day for(int x = 0; x < costperday.length-1; x++) { //sort cost per day array in descending order using bubble sort for(int j = x + 1; j < costperday.length; j++) { if(costperday[x] < costperday[j]) { int t = costperday[x]; costperday[x] = costperday[j]; costperday[j] = t; } } }
this code snippet. need print names of cars in descending order of corresponding cost.
thanks in advance!
string carmodel[] = {"a", "b", "c"}; //names of cars int costperday[] = {100, 75, 250}; //rental cost per day for(int x = 0; x < costperday.length-1; x++){ //sort cost per day array in descending order using bubble sort for(int j = x + 1; j < costperday.length; j++){ if(costperday[x] < costperday[j]){ int t = costperday[x]; string s = carmodel[x]; costperday[x] = costperday[j]; costperday[j] = t; carmodel[x] = carmodel[j]; carmodel[j] = s; } } } for(int x = 0; x < carmodel.length; x++){ system.out.println(carmodel[i]); }
Comments
Post a Comment