/*
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