Friday, 11 December 2020

Program in Java using Input Stream Reader Class.

 /* Question :-

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' and 'ga'. Calculate and display the following:

(i)  Percentage of girls present in the class.

(ii) Percentage of boys present in the class.

[Percentage must be calculated on the total number of Students]

*/

import java.io.*;

class Class

{

    public static void main(String args[])throws IOException

    {

    InputStreamReader read=new InputStreamReader(System.in);

    BufferedReader in=new BufferedReader(read);

    int b,g,ba,ga;

    float per_boys,per_girls;

    System.out.println("Enter the number of boys and girls in the class");

    b=Integer.parseInt(in.readLine());

    g=Integer.parseInt(in.readLine());

    System.out.println("Enter the number of boys and girls in the class who were absent");

    ba=Integer.parseInt(in.readLine());

    ga=Integer.parseInt(in.readLine());

    per_girls=(float)(g-ga)/(g+b)*100;

    per_boys=(float)(b-ba)/(g+b)*100;

    System.out.println("The Percentage of girls Present in the class : "+per_girls+"%");

    System.out.println("The Percentage of boys Present in the class : "+per_boys+"%");

    }

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...