Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that enters from the console number n and n strings,
- * then sorts them alphabetically and prints them. */
- import java.util.Arrays;
- import java.util.Scanner;
- public class _08_SortArrayOfStrings {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter a positive whole number of elements in your Sequence: ");
- int count = scan.nextInt();
- if (count > 0) {
- scan.nextLine();
- String[] arrStr = new String[count];
- for (int i = 0; i < arrStr.length; i++) {
- System.out.print("Enter the next word: ");
- arrStr[i] = scan.nextLine();
- }
- Arrays.sort(arrStr);
- System.out.println("The alphabetically sorted Sequence of these elements is:");
- for (String word : arrStr) {
- System.out.println(word);
- }
- } else {
- System.out.println("Error! - Invalid Input!!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement