1129 0

Compute the average kids per family. Note that the integers should be type cast to doubles.

Compute the average kids per family. Note that the integers should be typecast to doubles.

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 per family: “); System.out.println(avgKids); return; } }

Answer

TypeCasting.java

import java.util.Scanner;

public class TypeCasting {

public static void main(String[] args) {

int numKidsA = 1;

Crossword Puzzle
Crossword Puzzle

int numKidsB = 4;

int numKidsC = 5;

int numFamilies = 3;

double avgKids = 0.0;

avgKids = (numKidsA + numKidsB + numKidsC) /(double)numFamilies;

System.out.print(“Average kids per family: “);

System.out.println(avgKids);

return;

}

}

Output:

Average kids per family: 3.3333333333333335