Write a class named Sorting with sort function in order to sort the following array as program. Call sort function in main function. [4 marks]
char[] j= {'r', 'g', 'o', 'm', 'r', 'p','a'};
output display as “program”
public class Sorting {
public void sort(char[] array) {
System.out.print(array[5]);
System.out.print(array[4]);
System.out.print(array[2]);
System.out.print(array[1]);
System.out.print(array[0]);
System.out.print(array[6]);
System.out.print(array[3]);
}
}
public class Program {
public static void main(String[] args) {
char[] j = { 'r', 'g', 'o', 'm', 'r', 'p', 'a' };
Sorting sorting = new Sorting();
sorting.sort(j);
}
}
Comments
Leave a comment