一个简单的java程序,输入学生姓名,求他获得的三门科目的平均分
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class MyException extends Exception
{
MyException(String s)
{
super(s);
}
}
class Student
{
String name;
String inputName()
{
return name;
}
void average(int [] a)
{
int d;
if ((a.length)==3)
{
d = (a[0]+a[1]+a[2])/3;
if (d>50)
System.out.println(" Congratulations!!! "+name+ "
you have passed the examination");
else
System.out.println(" Oops " +name+" Try Later!!");
}
}
public static void main(String x[]) throws IOException
{
Student s= new Student();
int args[] =new int[3];
System.out.println("Enter name of the student:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s.name=br.readLine();
System.out.println("Name of the student is " +s.inputName().trim());
System.out.println("Marks in Physics = ");
args[0]=Integer.parseInt(br.readLine().trim());
System.out.println("Marks in Chemistry = ");
args[1]=Integer.parseInt(br.readLine().trim());
System.out.println("Marks in Mathematics = ");
args[2]=Integer.parseInt(br.readLine().trim());**$$**
s.average(args);**##**
}
}
代码没有错误。代码一直执行到$$ step,但是##指示的step没有执行。不知道为什么??