Monday, July 12, 2021

1 . Write a program to calculate percentage of a given student in CBSE board exam . His marks from 5 subjects must be taken as input from the keyboard. (Marks out of 100)

 import java.util.Scanner;


public class Main {

      public static void main(String[] args) {

Scanner S = new Scanner(System.in);

System.out.println("Enter your marks in English out of 100 : ");

float a = S.nextFloat();

System.out.println("Enter your marks in Science out of 100 : ");

float b = S.nextFloat();

System.out.println("Enter your marks in History out of 100 : ");

float c = S.nextFloat();

System.out.println("Enter your marks in Computer out of 100 : ");

float d = S.nextFloat();

System.out.println("Enter your marks in Hindi out of 100 : ");

float e = S.nextFloat();

float sum = a + b + c + d + e;

float avg = sum / 5;

System.out.println("The percentage is : " + avg);

     }

}


NOTE :

  • Needed Scanner class to take input from the user.
  • Used float because user can input marks with decimal number.
  • Took sum to calculate average.
  • Calculated average because (a + b + c + d + e)/500 * 100 since 500 and 100 can be                             divided the average marks is the percentage of the user. 


No comments:

Post a Comment