生成输出文本文件时出现扫描仪类错误 import java.io.*; 导入java.util.*; 班猫 { int t,n[],m[]; private void input()引发IOException { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 扫描仪s=新的扫描仪(System.in); t=Integer.parseInt(br.readLine()); n=新整数[t]; m=新整数[t]; 对于(int i=0;i

生成输出文本文件时出现扫描仪类错误 import java.io.*; 导入java.util.*; 班猫 { int t,n[],m[]; private void input()引发IOException { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 扫描仪s=新的扫描仪(System.in); t=Integer.parseInt(br.readLine()); n=新整数[t]; m=新整数[t]; 对于(int i=0;i,java,swing,console,Java,Swing,Console,,在使扫描仪移动到下一个元素之前,检查下一个元素是否存在始终是一种良好的做法。您可以通过添加以下代码行来执行此操作: import java.io.*; import java.util.*; class cat { int t,n[],m[]; private void input()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scann

,在使扫描仪移动到下一个元素之前,检查下一个元素是否存在始终是一种良好的做法。您可以通过添加以下代码行来执行此操作:

import java.io.*;
import java.util.*;
class cat
{
int t,n[],m[];
private void input()throws IOException
{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    Scanner s=new Scanner(System.in);
    t=Integer.parseInt(br.readLine());
    n=new int[t];
    m=new int[t];
    for(int i=0;i<t;i++)
    {
        n[i]=s.nextInt();//line 15
        m[i]=s.nextInt();
    }
}

private void calc(int n, int m)
{
    double c=0.0;
    if(n==1 && m==1)
        System.out.println("Multiple");
    else
    {
        c=((n*m)-1.0)/(n-1);
        if(c==Math.ceil(c))
            System.out.println(Math.round(c));
        else
            System.out.println("Not possible");
    }
}

public static void main(String args[])throws IOException
{
    cat ob=new cat();
    ob.input();
    for(int i=0;i<ob.t;i++)
    {
        ob.calc(ob.n[i],ob.m[i]);
    }
}
}

NoSuchElementException
在输入用尽时发生,即
扫描器中没有下一个元素
。它是指向相应Java API的链接。

您从哪里获取输入?根据您在文件中的解释,根据System.in中的代码。请澄清此问题以避免混淆。如果我理解您的意思,您正在读取第一个值,并将其用作数组
m
n
的大小。之后读取的值存储(交替)在两个数组中。正如Kakarot提到的,您应该使用
scanner.hasNextInt()
以确保输入可用。请务必考虑所有可能的情况,如i)根本没有输入可用,ii)数组的输入可用,以及iii)
n
avail的输入,但
m
的输入不可用。您还可以尝试捕获NoTouchElementException并将其出现解释为格式错误的输入数据的标准。
if(scanner.hasNextInt())
{
   // get nextInt(), next()....
   n[i]=s.nextInt();
}

if(scanner.hasNextInt())
{
    m[i]=s.nextInt();
}