In this program Roll Number and 4 subject marks of 5 students will be entered in separate 1 d arrays and display students equal to or above 80 % and below 80% separately
import java.io.*;
class Marks
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int roll[]=new int[5];
int eng[]=new int[5];
int math[]=new int[5];
int phy[]=new int[5];
int chem[]=new int[5];
int i,f,sum;
double av=0;
void take() throws IOException
{
for(i=0;i<5;i++)
{
System.out.print("\nRoll Number of Student Number "+(i+1)+":");
roll[i]=Integer.parseInt(br.readLine());;
System.out.print("\nEnglish Marks:");
eng[i]=Integer.parseInt(br.readLine());
System.out.print("\nMath Marks:");
math[i]=Integer.parseInt(br.readLine());
System.out.print("\nPhysics Marks:");
phy[i]=Integer.parseInt(br.readLine());
System.out.print("\nChemistry Marks:");
chem[i]=Integer.parseInt(br.readLine());
}
System.out.println("\nResult Sheet:");
System.out.println("\nRoll Eng Math Phy Chem");
for(i=0;i<5;i++)
{
if(roll[i]<10)
System.out.print("0"+roll[i]+" ");
else
System.out.print(roll[i]+" ");
if(eng[i]<10)
System.out.print("00"+eng[i]+" ");
else if (eng[i]<100)
System.out.print("0"+eng[i]+" ");
else
System.out.print(eng[i]+" ");
if(math[i]<10)
System.out.print("00"+math[i]+" ");
else if (math[i]<100)
System.out.print("0"+math[i]+" ");
else
System.out.print(math[i]+" ");
if(phy[i]<10)
System.out.print("00"+phy[i]+" ");
else if (phy[i]<100)
System.out.print("0"+phy[i]+" ");
else
System.out.print(phy[i]+" ");
if(chem[i]<10)
System.out.print("00"+chem[i]+" ");
else if (chem[i]<100)
System.out.print("0"+chem[i]+" ");
else
System.out.print(chem[i]+" ");
System.out.println();
// System.out.print("\n"+roll[i]+" "+eng[i]+" "+math[i]+" "+phy[i]+" "+chem[i]);
}
f=0;
System.out.print("\nStudents above 80%\n");
for(i=0;i<5;i++)
{
sum=eng[i]+math[i]+phy[i]+chem[i];
av=sum/4.0;
if(av>=80)
{
f=1;
System.out.println("\n "+roll[i]+": "+av);
}
}
if(f==0)
System.out.println("\nNo Student above 80%");
f=0;
System.out.print("\n\nStudents below 80%\n");
for(i=0;i<5;i++)
{
sum=eng[i]+math[i]+phy[i]+chem[i];
av=sum/4.0;
if(av<80)
{
f=1;
System.out.println("\n "+roll[i]+": "+av);
}
if(f==0)
System.out.println("\nNo Student below 80%");
}
}
public static void main(String args[]) throws IOException
{
Marks ob=new Marks();
ob.take();
}
}
No comments:
Post a Comment