考察输入的使用, 代码如下:
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; } } } }