所以它必须像下面的例子一样,扫描仪输入不同!
INPUT:
Two words word1, word2 each on separate lines.
OUTPUT:
Whichever word appears first in the dictionary
SAMPLE INPUT:
hello help
SAMPLE OUTPUT:
hello
答案 0 :(得分:1)
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String[] strings = { "anupam", "lucky", "hello", "help" };
Arrays.sort(strings);
}
}
或者如果你在arraylist中输入,那么程序将是:
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
ArrayList<String> list=new ArrayList<>();
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
for(int i=0;i<n;i++)
{
list.add(sc.next());
}
Collections.sort(list);
System.out.println(list);
}
}