Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中的数据类型转换错误_Java_Type Conversion - Fatal编程技术网

java中的数据类型转换错误

java中的数据类型转换错误,java,type-conversion,Java,Type Conversion,获取意外错误 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in) ; int number = input.nextInt() ; String word = input.nextLine(); String

获取意外错误

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in) ;
        int number = input.nextInt() ;

        String word = input.nextLine();

        String word1 = Integer.toString(number) ;
        int number1  = Integer.parseInt(word) ;

        if (number1 == Integer.parseInt(word) )
            {
            number1 = number + 10 ;
            System.out.println("Congratualtion its a number"+" "+ number1) ;
        }

            else if  (word1 == Integer.toString(number) )
               {  word1 = 10 + word ;
            System.out.println("Congratualtion its a word"+" "+ word1);
    }
        else
           System.out.println("Something is wrong !!! ") ;

}
}
错误消息:

Error : Exception in thread "main" java.lang.NumberFormatException: For input string: " "
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:481)
    at java.lang.Integer.parseInt(Integer.java:527)
    at Solution.main(Solution.java:13)

这是有问题的一行:
intnumber1=Integer.parseInt(word);

word
是非数字字符串;代码正在尝试将其转换为整数,但无法执行此操作。您可能希望打印出从
输入中获得的每件东西,并确保您拥有您认为拥有的东西


祝您好运。

NumberFormatException:对于输入字符串:“您注意到了吗?”?尝试正确输入数据为什么会出现意外情况?你以为会有不同的错误吗?为什么会投反对票?