q9722088 2017-06-11 08:14 采纳率: 54.5%
浏览 815
已采纳

java异常求助java异常求助java异常求助java异常求助

import java.util.HashMap;
import java.util.Scanner;

public class Milage {
HashMap CityName = new HashMap();
private int[][] milage;

public int SetCityName(){
    Scanner mc = new Scanner(System.in);
    int i = 0;
    String s = new String();
    s = mc.nextLine();
    while( true) {
        if( s.equals("###")) {
            break;
        }else {
            CityName.put(s, i);
            i++;
            s = mc.nextLine();
        }
    }
    mc.close();
    return i;
}

public void SetInt(int n) {
    Scanner sc = new Scanner(System.in);
    int miter;
    milage = new int[n][n];
    for( int i=0; i<n; i++) {
        for( int j=0; j<n; j++) {
            miter = sc.nextInt();
            milage[i][j] = miter;
        }
    }
    sc.close();
}

public int Getmil(String a,String b) {
    int f = CityName.get(a);
    int s = CityName.get(b);
    return milage[f][s];
}
public static void main(String[] args) {
    // TODO 自动生成的方法存根
    Scanner in = new Scanner(System.in);
    Milage m = new Milage();
    int n1 = m.SetCityName();
    m.SetInt(n1);
    String name1 = in.next();
    String name2 = in.next();
    System.out.println(m.Getmil(name1, name2));
    in.close();
}

}

输入:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Milage.SetInt(Milage.java:30)
at Milage.main(Milage.java:50)
错误语句 30:for( int i=0; i<n; i++) {
错误语句 50:String name1 = in.next();
debug到for的时候就报错了

  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 统信linux360企业浏览器 如何配置扩展程序?(图形界面我知道)
      • ¥100 c/c++实现DoubleArrayTrie
      • ¥30 关于#网络安全#的问题:非对称加密验证
      • ¥20 关于线性代数里施密特正交化和QR分解的疑问
      • ¥15 matlab超类包含解析错误
      • ¥15 python拖拽文件问题
      • ¥15 执行import paddle代码出现错误如何解决?
      • ¥15 hisat2align exited with value 137
      • ¥15 寻找大学生合作开发软件(Delphi)
      • ¥30 AndroidBench&eMMC内存测试速度&Android