未知格式转换异常运行时错误

我编写了一个程序,其中用户输入 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);

      }

    }

  }

}



慕斯王
浏览 165回答 1
1回答

噜噜哒

如果您想使用打印新行,printf那么您应该使用%n而不是\n&nbsp;docsA new line character appropriate to the platform running the application. You should always use %n, rather than \n.&nbsp;文档
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java