2015-09-19 76 views
0

我是一名新学员。为什么uva显示运行时错误?UVA Java运行时错误

import java.util.Scanner; 

public class Main { 

    public static void main(String[] args) { 

     int a, b, c, i, n; 

     Scanner d = new Scanner(System.in); 
     System.out.println("how many test"); 
     n = d.nextInt(); 

     for(i = 0; i <= n; i++) 
     { 
      Scanner s = new Scanner(System.in); 
      System.out.println("enter the value of a\n"); 
      a = s.nextInt(); 

      Scanner x = new Scanner(System.in); 
      System.out.println("enter the value of b\n"); 
      b = x.nextInt(); 

      Scanner z = new Scanner(System.in); 
      System.out.println("enter the value of c\n"); 
      c = z.nextInt(); 

      if(a>b && a<c || b>a && a>c) 
       System.out.println(a); 

      if(b>a && b<c || b<a && b>c) 
       System.out.println(b); 

      if(c>b && c<a || c>a && b>c) 
       System.out.println(c); 
     } 
    } 
} 
+0

这是个什么问题? – Gnarlywhale

回答

0

三个小建议对

  • 它实际上是读N + 1的情况下,改变 “< =” 到 “<” 的循环。

  • 无需每次阅读的时间来实例化一个新的扫描,删除所有 “新的扫描仪......”除了第一个,并且从那时起,使用该 之一,例如循环内的d.nextInt()。

  • 循环后关闭扫描仪:d.close();