Hi guys Just started programming so please bare with me.


So basically I created a program that adds and examines the difference between boys and girls in a room

here's the code:

///////////////////////////////////////////////////////////

import java.util.Scanner;
class Test{


public static void main(String args[]){
Scanner chris = new Scanner(System.in);

int girls, boys, Addition, difference;

System.out.println("Enter how many girls there are: ");
girls = chris.nextInt();
System.out.println("Enter how many boys there are: ");
boys = chris.nextInt();
Addition = girls + boys;
difference = Math.max(girls, boys) - Math.min(girls, boys);
System.out.print("The number of people in the building is: " );
System.out.println(Addition);
System.out.print("There are ");
System.out.print(difference);
System.out.print(" more ");
System.out.print(Math.max(girls, boys));
System.out.print(" Than ");
System.out.print(Math.min(boys, girls));
}

//////////////////////////////////////////////////////


So basically when the code runs it asks the user to enter in the amount of boys and girls there are.

Say I entered 20 girls and 10 boys

So the program will first return a line saying " The number of people in the building is: 30"

My issue is the next part

I want it to first find out if there are more boys and girls, which i figured out how to do using the Math.max and Math.min commands

So in this case I would like the line to read: "There are 10 more girls than boys"

but the only problem is that it is reading: "There are 10 more 20 than 10"
(20 being the amount of girls and 10 being the amount of boys)

I know exactly the program is doing this, I'm just not sure how to assign the number of Girls or boys to a string that only displays "Girls" or "Boys"

Sorry for the long read, if i confused you just throw the code into you're compiler and you'll figure out what I mean in seconds. Also any other tips on how I can clean up my code would be much appreciated

Thanks a lot for any help!

--- Update ---

Ah nevermind! Figured it out by using an If statement!

This is what my code ended up looking like:

import java.util.Scanner;
class Class{

public static void main(String args[]){
Scanner chris = new Scanner(System.in);

int girls, boys, peopleAdded, difference;

System.out.println("Enter how many girls there are: ");
girls = chris.nextInt();
System.out.println("Enter how many boys there are: ");
boys = chris.nextInt();
peopleAdded = girls + boys;
difference = Math.max(girls, boys) - Math.min(girls, boys);
System.out.print("The number of people in the building is: " );
System.out.println(peopleAdded);
if (boys > girls){
System.out.print("There are ");
System.out.print(difference);
System.out.println(" more boys than girls");

}

if (girls > boys){
System.out.print("There are ");
System.out.print(difference);
System.out.println(" more girls than boys");
}
if (girls == boys){
System.out.print("There are an equal amount of boys and girls");
}

}


}





Thanks anyways guys!