Write a program that asks the user to enter three names, and then displays the names sorted in ascending order. For example, if the user entered "Charlie", "Leslie", and "Andy", the program would display: Andy

Respuesta :

Answer:

Explanation:

//import the package

import java.util.Scanner;

import java.util.Arrays;

//create the arrays

private static String[] names = new String[3];

/we ask the 3 names

     Scanner scan = new Scanner(System.in);    

  System.out.println("You must enter 3 names");

  //a for cycle to get the names

  for(int i=0;i<names.length;i++){

   System.out.println("Enter name: ");

   names[i]= scan.next();

  }

               // we print in order

  scan.close();

  Arrays.sort(names);  

  System.out.println("Sorted List "+Arrays.toString(names));

}

}