In a class of ‘n’ number of students, the number of girls is ‘m’. Write a Java program to create a class named Percentage to perform the following tasks: (i) Input the values of n and m (Use Scanner Class) (ii) Calculate and display the following: Total no. of boys, percentage of boys and girls in the class.
Answers
Answered by
3
Answer:
package collection;
import java.util.Scanner;
public class SwapNumber {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int m,n;
System.out.println("Enter no. of boys in class");
m=sc.nextInt();
System.out.println("Enter no. of girls in class");
n=sc.nextInt();
System.out.println("Percentage of boys in class: "+(double)m/(m+n)*100+"%");
System.out.println("Percentage of girls in class: "+(double)n/(m+n)*100+"%");
}
}
Output:
Enter no. of boys in class
50
Enter no. of girls in class
123
Percentage of boys in class: 28.901735%
Percentage of girls in class: 71.09826589595376%
Similar questions