java ::;;:;;!
write a program input marks of 3 subjects calculate and print total and percentage if percentage is more than equal to 60 print "pass" else print "hard work needed"
Answers
Question:-
➡ Write a program input marks of 3 subjects calculate and print total and percentage if percentage is more than equal to 60 print "pass" else print "hard work needed".
Program:-
import java.util.*;
class PassFail
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double a, b, c, p;
System.out.println("Enter your marks in three subjects...");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
p=a+b+c;
System.out.println("Total Marks you scored: "+p);
p=p/3.0;
System.out.println("Percentage scored: "+p);
if(p>=60)
System.out.println("You passed the exam.");
else
System.out.println("You have failed. Hard work is needed. ");
}
}
Answer:
import java. util. *;
class Marks
{
public static void main(String ar[])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter marks of 3 subject") ;
int a=sc.nextInt() ;
int b=sc.nextInt() ;
int c=sc.nextInt() ;
double p=0.0;
p=((a+b+c) /300) *100; //calculating percentage....
if(p>=60.0)
System.out.println("Pass") ;
else
System.out.println("Hard work needed") ;
}
}
Explanation:
Note:-
- formula of percentage is Sum/Total*100
- Since we know we have to find percentage, it has to be declared in "double" type variable