Exercise 1 ---
"Percentage Calculation"
Q: Write a program to calculate percentage of a given student in board exam. His marks from 5 subjects must be taken as input from the keyboard.
Solution:
package com.company;
import java.util.Scanner;
public class Exr1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of Bengali");
int a = sc.nextInt();
System.out.println("Enter the number of English");
int b = sc.nextInt();
System.out.println("Enter the number of Mathematics");
int c = sc.nextInt();
System.out.println("Enter the number of Physics");
int d = sc.nextInt();
System.out.println("Enter the number of Chemistry");
int e = sc.nextInt();
System.out.println("Total");
float sum = a+b+c+d+e;
System.out.println(sum);
System.out.println("Percentage");
float percentage = (sum/500) * 100;
System.out.println(percentage);
}
}
Comments
Post a Comment