蓝桥试题 算法提高 P0101 JAVA

资源限制
时间限制:1.0s 内存限制:256.0MB
  
  一个水分子的质量是3.0*10-23克,一夸脱水的质量是950克。写一个程序输入水的夸脱数n(0 <= n <= 1e10),然后输出水分子的总数。
输入
  109.43
输出
  3.465283E+027
  
思路:https://blog.csdn.net/mcp3128/article/details/78633302

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double n = scanner.nextDouble();
		double ans = n * 950 / (Math.pow(10, -23) * 3);   // 题目公式
		int digit = 0;                                    // 判断指数位数
		while (ans > 10) {
			ans /= 10;
			digit++;                                      // 统计指数位数
		}
		System.out.printf("%.6f", ans);                   // 小数后六位
		System.out.print("E+0");                          // 输出E+0
		if (digit == 0) {                                 // 指数位数=0时,保证+后面是三位数
			System.out.println("0" + digit);
		} else {
			System.out.println(digit);
		}
	}
}

小剧场:总是喜欢,Always love.

发布了213 篇原创文章 · 获赞 450 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/weixin_43771695/article/details/105560317