2018/12/08 L1-040 最佳情侣身高差 Java

考察输入的使用, 代码如下:

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(br.readLine());
        String[][] people = new String[num][2];
        double finalNum;
        for(int i=0; i<num; i++) {
            people[i] = br.readLine().split(" ");
        }
//        // 测试
//        for (String[] s: people) {
//            System.out.println(s[0]+" " +s[1]);
//        }
        for (String[] s: people ) {
            if(s[0].charAt(0) == 'F') {
                finalNum = Double.parseDouble(s[1]) * 1.09;
                System.out.println(String.format("%.2f", finalNum));
            } else if(s[0].charAt(0) == 'M') {
                finalNum = Double.parseDouble(s[1]) / 1.09;
                System.out.println(String.format("%.2f", finalNum));
            } else {
                return;
            }
        }

    }

}

 

posted @ 2018-12-08 15:42  HHZZHH  阅读(645)  评论(0编辑  收藏  举报