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

什么是NumberFormatException以及如何解决?

什么是NumberFormatException以及如何解决?

什么是NumberFormatException以及如何解决?Error Message:Exception in thread "main" java.lang.NumberFormatException: For input string: "Ace of Clubs"    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)    at java.lang.Integer.parseInt(Integer.java:580)    at java.lang.Integer.parseInt(Integer.java:615)    at set07102.Cards.main(Cards.java:68)C:\Users\qasim\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1BUILD FAILED (total time: 0 seconds)我的循环:while (response != 'q' && index < 52) {    System.out.println(cards[index]);    int first_value = Integer.parseInt(cards[index]);    int value = 0;    //Add a Scanner    Scanner scanner = new Scanner(System.in);    System.out.println("Will the next card be higher or lower?, press q if you want to quit");    String guess = scanner.nextLine();    if(cards[index].startsWith("Ace")) { value = 1; }    if(cards[index].startsWith("2")) { value = 2; }    if(cards[index].startsWith("3")) { value = 3; }    //checking 4-10    if(cards[index].startsWith("Queen")){ value = 11; }    if(cards[index].startsWith("King")){ value = 12; }    if(guess.startsWith("h")){        if(value > first_value){ System.out.println("You answer was right, weldone!"); }         else { System.out.println("You answer was wrong, try again!"); }    } else if(guess.startsWith("l")){        if(value < first_value) { System.out.println("You answer as right, try again!"); }        else { System.out.println("You answer was wrong, try again!"); }    } else { System.out.println("Your was not valid, try again!"); }    scanner.close();                index++;}//end of while loop
查看完整描述

3 回答

?
杨__羊羊

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

貌似cards[]字符串数组,你正试图转换Ace of Clubs整数

int first_value = Integer.parseInt(cards[index]);


查看完整回答
反对 回复 2019-05-27
  • 3 回答
  • 0 关注
  • 13574 浏览

添加回答

举报

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