A simple java program to input the name of student and find the average of marks of three subjects obtained by him
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);**##**
}
}
The code has no errors.The code is executing till $$ step ,but the step indicated with ## is not executing.I don’t know why??
Following is the output of a test run:
So, the method is actually executing but the reason you are not seeing any output is, just like others have pointed out, the following condition is not satisfied
Also it would be nice to add else part as follows: