2008年4月14日 星期一

Average income by gender (補交)

import java.util.Scanner;

public class AverageIncomeByGender
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter the sex and income");

double woman=0,man=0;
int f=0,m=0;
String key="y";
do
{
String sex = keyboard.next();
double income=0;
if(sex.equals("m"))
{
income = keyboard.nextDouble();
man=man+income;
m++;
}
else if (sex.equals("f"))
{
income = keyboard.nextDouble();
woman=woman+income;
f++;
}
else
{
System.out.println(f+" women's average income is "+(woman/f)+"元");
System.out.println(m+" men's average income is "+(man/m)+"元");
System.out.println("Do you have another data to input?(y/n)");
key=keyboard.next();
}
}
while(key.equals("y"));
}
}

結果:











p.s.忘記交了~sorry~

沒有留言: