Java语言程序设计基础篇编程练习题2.11示例代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38234015/article/details/88316405
import java.util.Scanner;

public class Test2_11 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the number of years: ");
		int years = input.nextInt();
		input.close();
		int num = 312032486;
		int time = 3600 * 24 * 365;
		int birth = time / 7;
		int die = time / 13;
		int in = time / 45;
		int change = birth + in - die;
		for(int i = 0; i < years; i++) {
			num += change; 
		}
		System.out.println("The population in " + years + " years is " + num);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38234015/article/details/88316405