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;

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

[wordpress_social_login]


OR


Note: Your password will be generated automatically and sent to your email address.

Forgot Your Password?

Enter your email address and we'll send you a link you can use to pick a new password.