为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕斯王 2021-10-20 15:04:26
我编写了一个程序,其中用户输入 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);      }    }  }}
查看完整描述

1 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

如果您想使用打印新行,printf那么您应该使用%n而不是\n docs

A new line character appropriate to the platform running the application. You should always use %n, rather than \n. 文档


查看完整回答
反对 回复 2021-10-20
  • 1 回答
  • 0 关注
  • 164 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信