Calculate the average number of kids per family. Note that the integers should be type cast to doubles. Calculate the average number of children per family. Be sure to type cast the integers to doubles.
Table of Contents
Average Kids Per Family
import java.util.Scanner;
public class TypeCasting {
public static void main (String [] args)
{
int numKidsA = 1;
int numKidsB = 4;
int numKidsC = 5;
int numFamilies = 3;
double avgKids = 0.0;
System.out.print(“Average kids: “);
System.out.println(avgKids);
return;
}
}
Answer
Type Casting.java
import java.util.Scanner;
public class TypeCasting {
public static void main(String[] args) {
int numKidsA = 1;
int numKidsB = 4;
int numKidsC = 5;
int numFamilies = 3;
double avgKids = 0.0;
avgKids = (numKidsA + numKidsB + numKidsC) /(double)numFamilies;
System.out.print(“kids per family: “);
System.out.println(avgKids);
return;
}
}