We thoroughly check each answer to a question to provide you with the most correct answers. Found a mistake? Tell us about it through the REPORT button at the bottom of the page. Ctrl+F (Cmd+F) will help you a lot when searching through such a large set of questions.
/*
4.3.1: Type casting: Computing average kids per family
Compute the average kids per family. Note that the integers should be type cast to doubles.
*/
Answer
import java.util.Scanner;
public class TypeCasting {
public static void main (String [] args) {
int numKidsA;
int numKidsB;
int numKidsC;
int numFamilies;
double avgKids;
numKidsA = 1;
numKidsB = 4;
numKidsC = 5;
numFamilies = 3;
avgKids = (numKidsA + numKidsB + numKidsC) / (double)(numFamilies);
/* Solution above */
System.out.print("Average kids per family: ");
System.out.println(avgKids);
}
}
Output: Average kids per family: 3.3333333333333335
Was this helpful?
Let us know if this was helpful. That’s the only way we can improve.