Compute The Average Kids Per Family. Note That The Integers Should Be Type Cast To Doubles.

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?

quizzma
Quizzma Team
+ posts

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.