a class contains b number of boys and g number of girls .on a rainy day ba number of boys and ga number of girls are absent write a program to input the values of b,g,ba,ga calculate and display the following
I) percentage of girls present in the class
ii) percentage of boys present in the class
Answers
Answer:
import java.util.*;
class CLASS
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of boys");
int b = sc.nextInt();
System.out.println("Enter the number of girls");
int g = sc.nextInt();
int total = b+g;
double ba = (b*100.0)/total;
double ga = (g*100.0)/total;
System.out.println("Number of boys absent on rainy day " +ba);
System.out.println("Number of girls absent on rainy day " +ga);
}
}
Answer:
import java.util.Scanner;
public class percentage
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no. of boys: ");
int b = sc.nextInt();
System.out.println("Enter the no. of girl: ");
int g = sc.nextInt();
int total = b + g;
System.out.println("Enter the no. of boys absent :");
int ba = sc.nextInt();
System.out.println("Enter the no. of girls absent :");
int ga = sc.nextInt();
double percentage_ba = (ba*100.0)/total;
double percentage_ga = (ga*100.0)/total;
double percentage_bp = 100.0 - percentage_ba; // bp = boys present
double percentage_gp = 100.0 - percentage_ga; // gp = girls present
System.out.println("Boys present = "+ percentage_bp + "%");
System.out.println("Girls present = " + percentage_gp + "%");
} // method ends here
} // class ends here
Explanation:
I hope it will help you!