java.util.NoSuchElementException异常

时间:2018-04-10 23:26:28

标签: java nosuchelementexception

我收到以下错误,无法解决投掷原因:

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at exam.main(exam.java:11)

以下是代码:

import java.util.*;
public class Exam {

    public static void main(String[] args) {
        int a;
        int b;
        Random rd=new Random();
        Scanner input  = new Scanner(System.in);
        System.out.println("Enter the number of rows");
        a=input.nextInt();
        System.out.println("Enter the number of columns");
        b=input.nextInt();

        int[][]arr=new int[a][b];
        int x = arr.length;
        int y = arr[0].length;
        for(int i=0;i<x;i++) {
            for(int c=0;c<y;c++) {
                arr[i][c]=rd.nextInt();
            }
        }
        for(int i=0;i<x;i++) {
            for(int c=0;c<y;c++) {
                System.out.println(arr[i][c]);
            }
        }
    }
}

0 个答案:

没有答案