PAT团队程序设计天梯赛L1-040 最佳情侣身高差

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38234015/article/details/85796112

题目要求

题目分析

利用最先输入的数字进行循环,接收剩余的输入,先接收字母,根据字母对后面的数字进行运算,然后为了便于输出,将运算的结果存储到数组中。

示例代码

import java.util.Scanner;

public class L1_040 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		double[] arr = new double[size];
		for(int i = 0; i < size; i++) {
			String s = sc.next();
			double height = sc.nextDouble();
			if(s.equals("M")) {
				arr[i] = height / 1.09;
			}
			if(s.equals("F")) {
				arr[i] = height * 1.09;
			}
		}
		for(int i = 0; i < size; i++) {
			System.out.printf("%.2f",arr[i]);
			System.out.println();
		}
		sc.close();
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38234015/article/details/85796112