Google Search

Monday, March 2, 2015

Write a Java Program to find calculate sum, average and check if pass or fail

ALGORITHM:

Step 1: Start

Step 2: Read marks in five subjects Step 3: Sum=m1+m2+m3+m4+m5 Step 4: Avg = sum/5f

Step 5: Print the sum and average

Step 6: If (m1>40) and (m2>40) and(m3>40) and(m4>40) and(m5>40) then pass else fail Step 8: Stop

PROGRAM: import java.io.*; class mark

{

public static void main(String args[])throws IOException

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int m1,m2,m3,m4,m5,tot;
float avg;

System.out.println("Enter the mark"); m1=Integer.parseInt(br.readLine()); m2=Integer.parseInt(br.readLine()); m3=Integer.parseInt(br.readLine()); m4=Integer.parseInt(br.readLine()); m5=Integer.parseInt(br.readLine()); tot=m1+m2+m3+m4+m5;avg=tot/5; System.out.println("Total="+tot); System.out.println("Average="+avg); if((m1>=40)&&(m2>=40)&&(m3>=40)&&(m4>+40)&&(m5>=40))




{

System.out.println("Result=Pass");

if (avg>=60){System.out.println("Class=First");} else if (avg>=50) {System.out.println("Class=Second");}

else {System.out.println("Class=Third");
}}

else {System.out.println("Result=Fail"); }



9


}

}

OUTPUT:

D:\JAVA>javac mark.java D:\JAVA>java mark Enter the mark

80

80

80

80

80

Total=400

Average=80.0

Result=Pass

Class=First


D:\JAVA>

0 comments:

Post a Comment