题解 | #牛牛的短信#
牛牛的短信
https://www.nowcoder.com/practice/435c9e2bf4f84bee99b82ce84e95b0b7
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n = in.nextInt(); double totalCost = 0; // 总费用 // 读取每条短信的字数并计算费用 for (int i = 0; i < n; i++) { int smsLength = in.nextInt(); if (smsLength <= 60) { totalCost += 0.1; } else { totalCost += 0.2; } } // 输出总费用 System.out.printf("%.1f\n", totalCost); } }