Attendance Percentage Calculator in Java
Calculate attendance percentage and decide if a student is allowed to sit in exam.
BeginnerModule 2: Conditional ProgramsExample 17 of 20
attendance-percentage-calculator.java
1import java.util.Scanner;23public class Main {4 public static void main(String[] args) {5 Scanner sc = new Scanner(System.in);67 System.out.print("Enter total classes held: ");8 int held = sc.nextInt();9 System.out.print("Enter total classes attended: ");10 int attended = sc.nextInt();1112 double per = (attended * 100.0) / held;13 System.out.println("Attendance = " + per + "%");1415 if (per >= 75.0) {16 System.out.println("Allowed to sit in exam");17 } else {18 System.out.println("Not allowed to sit in exam");19 }2021 sc.close();22 }23}
Output
Enter total classes held: 100 Enter total classes attended: 80 Attendance = 80.0% Allowed to sit in exam
What's going on
We compute attendance percentage and compare with a threshold (75%).