Need help =)..
Question: Write a program that reads in four strings and prints the lexicographically smallest and largest one:
enter four strings:
Charles
Alex
Delta
Baker
Output: The Lexicographic minimum is Alex.
The Lexicographic maximum is Delta.
//project import java.util.Arrays; import java.io.*; public class testing { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String name1,name2,name3,name4; System.out.println("Enter 1st: "); name1 = br.readLine(); System.out.println("Enter 2st: "); name2 = br.readLine(); System.out.println("Enter 3st: "); name3 = br.readLine(); System.out.println("Enter 4st: "); name4 = br.readLine(); String[] names = {name1,name2,name3,name4}; Arrays.sort(names); System.out.println(Arrays.toString(names)); } }
my program only sort the names.. can someone help me or give me a hint on how can i give the output(" The Lexicographic minimum is Alex. The Lexicographic maximum is Delta.")
because i dont have any idea on how can i pick the minimum and maximum.. i dont know what will i do to my first program.. help me T_T
thanks in advance =)