Ok so my problem should have a fairly simple fix. My program takes the number of families and their income and prints the families that make less than 10% of the maximum income. Below is a sample run.
Please enter the number of families:
5
Enter an income:
8500
Enter an income:
109000
Enter an income:
49000
Enter an income:
9000
Enter an income:
67000
Your maximum income is 109000
The incomes of families making less than 10% of the maximum are: 8500
The incomes of families making less than 10% of the maximum are: 9000
Total of: 2 Families.
What it should look like
Your maximum income is 109000
The incomes of families making less than 10% of the maximum are:
8500
9000
Total of: 2 Families.
Code:
//Dalton Kennedy
import java.util.*;
public class CountFamilies {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
int numberOfFamilies = 0;
int max = 0, less = 0;
System.out.println("Please enter the number of families:");
numberOfFamilies = kbd.nextInt();
long [] income = new long [numberOfFamilies];
for (int count = 0; count < numberOfFamilies; count++)
{
System.out.println("Enter an income:");
income[count]=kbd.nextLong();
}
for (int count = 0; count < income.length; count++)
{
int i = (int) income[count];
if (i > max)
{
max = i;
}
}
System.out.println("Your maximum income is" + " " + max + '\n');
int tenPer = (int) (max * .1);
for (int count = 0; count < income.length; count++)
{
if(income[count]< tenPer)
{
System.out.println("The incomes of families making less than 10% of the maximum are: " + '\n');
less++;
}
}
System.out.println("Total of: " + less + " Families.");
}
}