我编写了一个程序,其中用户输入 3 个 4 位十六进制数,然后使用 String 方法按大小对它们进行排序。我收到一个我不熟悉的错误。系统编译但运行时出错。我将发布我的源代码和错误
import java.util.Scanner;
public class HexNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three 4-digit hexadecimal numbers: ");
String numbers = input.nextLine();
String[] result = numbers.split("\\s+");
String a = result[0];
String b = result[1];
String c = result[2];
String A = a.toUpperCase();
String B = b.toUpperCase();
String C = c.toUpperCase();
int comp1 = C.compareTo(A);
int comp2 = C.compareTo(B);
int comp3 = B.compareTo(A);
boolean first = comp2 > comp1 && comp1 > 0 && comp2 > 0;
boolean second = comp1 <0 && comp2 < 0 && comp2 > comp1;
boolean third = comp1 > 0 && comp2 > 0 && comp1 == comp2;
boolean fourth = comp1 < 0 && comp2 < 0 && comp1 == comp2;
if(first = true){
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", C, A, B);
}
else if (second = true) {
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", A, B, C);
}
else if (third = true) {
if (comp3 > 0){
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", C, B, A);
}
else{
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", C, A, B);
}
}
else if (fourth = true) {
if (comp3 > 0){
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", B, A , C);
}
else{
System.out.printf("Maximum: %/s /n Median: %/s /n Minimum: %/s /n", A, B, C);
}
}
}
}
噜噜哒
相关分类