0
0

More than 3 years have passed since last update.

Main.java

Posted at

mport java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("何人分の情報を入力しますか:");
int n = scanner.nextInt();

int maxAge = 0;
int totalAge = 0;
for(int i = 0; i < n; i++){
  System.out.println(i + 1 + "人目");

  System.out.print("名前:");
  String firstName = scanner.next();

  System.out.print("名字:");
  String lastName = scanner.next();

  System.out.print("年齢:");
  int age =scanner.nextInt();

  if(age >maxAge){
    maxAge = age;
  }
  totalAge += age;

  System.out.print("身長(m):");
  double height = scanner.nextDouble();

  System.out.print("体重(kg):");
  double weight = scanner.nextDouble();

  Person.printData(firstName,lastName,age,height,weight);
  }
  System.out.println("最高年齢は"+maxAge+"歳です");
  System.out.println("平均年齢は"+totalAge/n+"歳です");
}

}

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0