当前位置: 代码迷 >> Java相关 >> 为什么不能运行?
  详细解决方案

为什么不能运行?

热度:201   发布时间:2007-03-27 20:27:15.0
为什么不能运行?

import java.io.*;
public class tongji {

public static void main(String[] args) //throws IOException
{
String str1,str2,str3,str4,str5;
int x=0,z=0,i=0,y=0;
int a[]=new int[5];
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("输入成绩:");
str1=buf.readLine();
a[0]=Integer.parseInt(str1);
System.out.print("输入成绩:");
str2=buf.readLine();
a[1]=Integer.parseInt(str2);
System.out.print("输入成绩:");
str3=buf.readLine();
a[2]=Integer.parseInt(str3);
System.out.print("输入成绩:");
str4=buf.readLine();
a[3]=Integer.parseInt(str4);
System.out.print("输入成绩:");
str5=buf.readLine();
a[4]=Integer.parseInt(str5);
do
{
if (a[i]<0 || a[i]>100)
//JOptionPane.showMessageDialog(null, "shurucuowu!");
System.out.print("输入错误!");
if (a[i]>=0 && a[i]<60)
x=x+1;
if (a[i]>=60 && a[i]<=75)
y=y+1;
if (a[i]>75 && a[i]<=100)
z=z+1;
i++;
}while(i<5);
System.out.println("A="+z);
System.out.println("B="+y);
System.out.println("C="+x);
}


}
可以正常运行。但是下面的就不运行

import java.io.*;
public class tongji {

public static void main(String[] args) //throws IOException
{
String str1,str2,str3,str4,str5;
int x=0,z=0,i=0,y=0;
int a[]=new int[5];
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("输入成绩:");
str1=buf.readLine();
a[0]=Integer.parseInt(str1);
System.out.print("输入成绩:");
str2=buf.readLine();
a[1]=Integer.parseInt(str2);
System.out.print("输入成绩:");
str3=buf.readLine();
a[2]=Integer.parseInt(str3);
System.out.print("输入成绩:");
str4=buf.readLine();
a[3]=Integer.parseInt(str4);
System.out.print("输入成绩:");
str5=buf.readLine();
a[4]=Integer.parseInt(str5);
while(i<5)
{
if (a[i]<0 || a[i]>100)
System.out.print("输入错误!");
if (a[i]<60)
x=x+1;
if (a[i]>=60 && a[i]<=75)
y=y+1;
if (a[i]>75)
z=z+1;
i++;
}
System.out.println("A="+z);
System.out.println("B="+y);
System.out.println("C="+x);
}


}

搜索更多相关的解决方案: 运行  

----------------解决方案--------------------------------------------------------
你没有捕获异常,怎么会正常运行?
----------------解决方案--------------------------------------------------------
基本的异常处理问题

当有非运行时异常的时候,需要做如下两点中的一点:
1,你的方法声明抛出这个异常
2,你在方法里面用 trycatch块捕获并处理可能抛出的异常
----------------解决方案--------------------------------------------------------

有关I/O操作的,都要捕抓异常,或抛出异常.


----------------解决方案--------------------------------------------------------
  相关解决方案