Thins是我到目前为止所拥有的。但我需要在不使用数组的情况下按字母顺序排列所有四个单词,而只使用带有 if 和 else 语句的字符串。
import java.util.Scanner;
public class Dictionary
{
public static void main (String[] args)
{
String word1, word2, word3, word4;
Scanner scan = new Scanner (System.in);
System.out.println ("Enter Four Words: ");
word1 = scan.next();
word2 = scan.next();
word3 = scan.next();
word4 = scan.next();
int compare = word1.compareTo(word2);
if (compare < 0)
{System.out.println(word1 + " " + word2);}
else if (compare > 0)
{System.out.println(word2 + " " + word1);}
}
}