Answer to Question #168858 in Databases | SQL | Oracle | MS Access for Chandra sena reddy

Question #168858

Get the number of male and female premium users in the platform.


Table: USER

user_id	   name	         gender	age	country	    premium_membership
2000	John White	       M	63	AUSTRALIA	      1
2001	John Andrews	   M	67	AUSTRALIA	      1
2002	April Robinson	   F	60	SRILANKA	      1
2003	Kathy Ryan	       F	81	SRILANKA	      0
2004	Megan Bradshaw	   F	53	AUSTRALIA	      1
2005	Melissa Sullivan   F	45	BANGLADESH	      1
2006	Amber Smith	       F	97	BANGLADESH	      0
2007	Sara Higgins	   F	85	ENGLAND	          1
2008	Robert Taylor	   M	68	AMERICA	          0
2009	William Wagner	   M	16	AMERICA       	  0
2010	Herbert Mcdowell   M	97	BANGLADESH    	  1
2011	Brett Carter	   M	26	AUSTRALIA	      0 
2012	Brian Knight	   M	81	AUSTRALIA	      1
2013	Jennifer Johnson   F	46	SRILANKA	      0
2014	Clarence Gonzales  M	92	SRILANKA	      0

there is still having lot of data in the table, but I just gave the limited data for example to get the solution related to question.

and the expected output format should be as follows:


Table:

gender	total_users
   F	  ...
   M	  ...




1
Expert's answer
2021-03-05T17:54:26-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int males, females;
        System.out.print("Enter the number of males: ");
        males = sc.nextInt();
        System.out.print("Enter the number of females: ");
        females = sc.nextInt();

        int percentageMales = Math.round(males * 100 / (males + females));
        System.out.println("Percentage males: " + percentageMales);
        System.out.println("Percentage females: " + (100 - percentageMales));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS