starstarzhang @ 2023-12-02 20:12:14
一直错不知道怎么回事,后面才发现c++的double格式有6位有效数字,我有一个一个打印出来看保留几位小数。
import java.util.Scanner;
/**
* @author: xingzhi
* @create: 2023-11-30 19:17
* @Description:
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
if (T == 1) {
System.out.println("I love Luogu!");
} else if (T == 2) {
System.out.println(6 + " " + 4);
} else if (T == 3) {
System.out.println(14/4);
System.out.println(14 - 14%4);
System.out.println(14 % 4);
} else if (T == 4) {
System.out.println(String.format("%7.3f", 500.0/3));
} else if (T == 5) {
System.out.println((260 + 220) / (12 + 20));
} else if (T == 6) {
System.out.println(String.format("%.4f", Math.sqrt(6*6 + 9*9)));
} else if (T == 7) {
System.out.println("110\n90\n0");
} else if (T == 8) {
double pi = 3.141593;
System.out.println(String.format("%.4f", 10 * pi));
System.out.println(String.format("%.4f", 25 * pi));
System.out.println(String.format("%.3f", 4.0 / 3 * pi * 125));
} else if (T == 9) {
System.out.println((((1 + 1) * 2 + 1) * 2 + 1) * 2 );
} else if (T == 10) {
System.out.println(9);
} else if (T == 11) {
System.out.println(String.format("%.4f", 100.0/3));
} else if (T == 12) {
System.out.println(('M' - 'A') +1);
System.out.println((char)('A' + 18 -1));
} else if (T == 13) {
double pi = 3.141593;
double s = 4.0 / 3 * 64 * pi + 4.0 / 3 * 1000 *pi;
System.out.println((int)Math.pow(s, 1.0/3));
} else if (T == 14) {
System.out.println(50);
}
}
}