Get premium membership and access questions with answers, video lessons as well as revision papers.
//Sort an array of string in reverse order.
Import java.until *;
//Create a Comparator that returns the outcome
//of a reverse string comparison.
Class RevStrComp implements Comprator {
//Implement the compare () method so that it
//reverses the order of the string comparison.
publicint compare(String strA, strB) {
//ComparestrB to strA, rather than strA to strB.
returnstrB.compareTo(strA);
}
}
//Demonstrate the reverse string comparator.
Class RevStrSort {
Public static void main(String[] args);{
//Create a sample array of strings
String strs[] = { “dog”, “horse”, “zebra”, “cow”, “cat” };
//show the initial order.
System.out.print(“Initial order: ‘’);
for (String s : strs)
System.out.print (s + “”);
System.out.println(‘’\n’’);
//Sort the array in reverse order
//Begin by creating a reverse string comparator.
RevStrComprsc = new RevStrComp();
//Now sort the string using the reverse comparator
Arrays.sort (strs, rsc);
//Show the reverse sorted order.
System.out.print (Sorted in reverse order: ‘’);
For(String s : strs)
System.out.print(s + ‘’ ‘’);
System.out.println(‘’\n’’);
//For comparison, sort the strings in natural order.
Arrays.Sort(strs);
//Show the natural sorted order.
System.out.print(‘’Sorted in natural order: ‘’);
for (String s : strs)
System.out.print(s + ‘’ ‘’);
System.out.println(‘’\n’’);
}
}
Githiari answered the question on January 26, 2018 at 12:11
- State TWO main ways through which data is accessed in a storage media and give an example of a storage media in each case.(Solved)
State TWO main ways through which data is accessed in a storage media and give an example of a storage media in each case.
Date posted: January 26, 2018. Answers (1)
- What is a repeater?(Solved)
What is a repeater?
Date posted: January 26, 2018. Answers (1)
- Define the following terms (a)attenuation (b)bandwidth (c)multiplexing(Solved)
Define the following terms (a)attenuation (b)bandwidth (c)multiplexing
Date posted: January 26, 2018. Answers (1)
- Which device is used to rectify attenuation in a transmission medium?(Solved)
Which device is used to rectify attenuation in a transmission medium?
Date posted: January 26, 2018. Answers (1)
- State and briefly explain modes of data communication(Solved)
The student should have understood computer networking and the modes of communications used.
Date posted: January 26, 2018. Answers (1)
- State and explain the types of computer networks(Solved)
State and explain the types of computer networks.
Date posted: January 26, 2018. Answers (1)
- State FOUR purposes of computer networks(Solved)
State FOUR purposes of computer networks.
Date posted: January 26, 2018. Answers (1)
- State THREE advantages of computer networks(Solved)
State THREE advantages of computer networks.
Date posted: January 26, 2018. Answers (1)
- State TWO advantages of distributed processing(Solved)
State TWO advantages of distributed processing.
Date posted: January 26, 2018. Answers (1)
- Define data signal as used in computer networking(Solved)
Define data signal as used in computer networking.
Date posted: January 26, 2018. Answers (1)
- Define a transmission media(Solved)
Define a transmission media.
Date posted: January 26, 2018. Answers (1)
- State THREE causes of computerised system failure. (Solved)
State THREE causes of computerised system failure.
Date posted: January 26, 2018. Answers (1)
- State the THREE core principles of data security(Solved)
State the THREE core principles of data security.
Date posted: January 26, 2018. Answers (1)
- State TWO advantages of high level languages(Solved)
State TWO advantages of high level languages.
Date posted: January 26, 2018. Answers (1)
- State two types of each program control structure( a)Selection (b)Iteration(Solved)
State two types of each program control structure( a)Selection (b)Iteration
Date posted: January 26, 2018. Answers (1)
- State THREE methods of debugging applied during testing and debugging stage of program development(Solved)
State THREE methods of debugging applied during testing and debugging stage of program development.
Date posted: January 26, 2018. Answers (1)
- State and explain TWO types of errors that can occur during the coding stage of program development(Solved)
State and explain TWO types of errors that can occur during the coding stage of program development.
Date posted: January 25, 2018. Answers (1)
- State SIX stages of program development.(Solved)
State SIX stages of program development.
Date posted: January 25, 2018. Answers (1)
- Write the following abbreviations in full. (a)BASIC (b)FORTRAN (c)COBOL(Solved)
Write the following abbreviations in full. (a)BASIC (b)FORTRAN (c)COBOL
Date posted: January 25, 2018. Answers (1)
- Give an example of Object Oriented Programming language(Solved)
A student is supposed to know different programming languages.
Date posted: January 25, 2018. Answers (1)