165k views
4 votes
In java - compute the average kids per family. note that the integers should be type cast to doubles.

User ChiakiYu
by
8.0k points

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class TypeCasting {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int numKidsA;

int numKidsB;

int numKidsC;

int numFamilies;

double avgKids;

numKidsA = scnr.nextInt();

numKidsB = scnr.nextInt();

numKidsC = scnr.nextInt();

numFamilies = scnr.nextInt();

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

System.out.println(avgKids);

}

}

Step-by-step explanation:

User Eber Freitas Dias
by
7.8k points