I wrote this code, but I want to know how to alphabetize the monthsusing the com
ID: 3618226 • Letter: I
Question
I wrote this code, but I want to know how to alphabetize the monthsusing the compareTo() method (I know this way is easier but I'dlike to know how to do it the tedious way).import java.util.*;
/**
* Write a description of class LongestMonthFinder here.
*
* @author (Alex Ramos)
* @version (4/19/10)
*/
public class Alphabetized{
public static void main(String[] args){
String[] months ={"January", "February", "March"
,"April", "May", "June", "July"
,"August", "September","October"
,"November", "December"};
Arrays.sort(months);
System.out.println(Arrays.toString(months));
}
}
Explanation / Answer
There are several sorting algorithms. Below is the selection sort. public staticvoid alphabetize(String[]months) { for(int i= 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.