-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpercentagecalc.java
More file actions
27 lines (20 loc) · 805 Bytes
/
percentagecalc.java
File metadata and controls
27 lines (20 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//this program calculates percentage from marks
import java.util.Scanner;
public class percentagecalc {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the marks obtained: ");
int obtainedMarks = scanner.nextInt();
System.out.print("Enter the total marks: ");
int totalMarks = scanner.nextInt();
double percentage = calculatePercentage(obtainedMarks, totalMarks);
System.out.println("The percentage of marks obtained is: " + percentage + "%");
}
public static double calculatePercentage(int obtainedMarks, int totalMarks) {
if (totalMarks == 0) {
return 0.0;
} else {
return (obtainedMarks * 100.0) / totalMarks;
}
}
}