简体   繁体   English

线程“main”java.lang.NumberFormatException中的异常:

[英]Exception in thread “main” java.lang.NumberFormatException:

I am executing my code in java But I am getting number exception error everytime. 我在java中执行我的代码但是我每次都会收到数字异常错误。 Please help 请帮忙

class TestClass {
public static void main(String args[]) throws IOException {
  BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
  String input = inp.readLine();
  //Scanner sc = new Scanner(System.in);
  StringTokenizer stk = new StringTokenizer(input);
  int n = Integer.parseInt(stk.nextToken());
  int q = Integer.parseInt(stk.nextToken());
  int [] arr = new int[n];
  int [] st = new int [n];
  for(int i =0;i<n;i++){
    arr[i] = Integer.parseInt(stk.nextToken());
     st[i] = fib(arr[i]);

  }  
while(q>0){
    int l = Integer.parseInt(stk.nextToken());
    int r = Integer.parseInt(stk.nextToken());
     System.out.println(gcd(st,l,r));
    q--;
}

I am continuously getting error message: 我不断收到错误消息:

Exception in thread "main" java.lang.NumberFormatException: For input string: "3 2" 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 TestClass.main(Main.java:14) 线程“main”中的异常java.lang.NumberFormatException:对于java.lang.Integer.parseInt(Integer.java:580)中java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)的输入字符串:“3 2”在TestClass.main的java.lang.Integer.parseInt(Integer.java:615)中(Main.java:14)

Try to use split method instead: 尝试使用拆分方法:

Instead of: 代替:

StringTokenizer stk = new StringTokenizer(input); StringTokenizer stk = new StringTokenizer(input);

int n = Integer.parseInt(stk.nextToken()); int n = Integer.parseInt(stk.nextToken());

int q = Integer.parseInt(stk.nextToken()); int q = Integer.parseInt(stk.nextToken());

Use: 采用:

String in[] = input.split(" "); [] = input.split(“”)中的字符串;

int n = Integer.parseInt(in[0]); int n = Integer.parseInt(在[0]中);

int q = Integer.parseInt(in[1]); int q = Integer.parseInt(在[1]中);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java-线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“”位于 - java - Exception in thread “main” java.lang.NumberFormatException: For input string: “” at 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:Java中的“” - Exception in thread “main” java.lang.NumberFormatException: For input string: “” in Java Java编程中的错误线程“主”中的异常java.lang.NumberFormatException - error in java programming Exception in thread “main” java.lang.NumberFormatException 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“ 0.06” - Exception in thread “main” java.lang.NumberFormatException: For input string: “0.06” 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“8/3/2012” - Exception in thread "main" java.lang.NumberFormatException: For input string: "8/3/2012" 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“” - Exception in thread “main” java.lang.NumberFormatException: For input string: “” 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“0.353” - Exception in thread “main” java.lang.NumberFormatException: For input string: “0.353” 线程“ main”中的异常java.lang.NumberFormatException:空 - Exception in thread “main” java.lang.NumberFormatException: null 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“; - Exception in thread “main” java.lang.NumberFormatException: For input string: "; 线程“main”中的异常java.lang.NumberFormatException:不是版本:9 - Exception in thread “main” java.lang.NumberFormatException: Not a version: 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM