JAVA作业

来源:互联网 发布:自动归类的软件 编辑:程序博客网 时间:2024/06/04 00:20

题目2006年培养学员8万人,每年增长25%,请问按照次增长速度,到哪一年培养学员人数将达到20万人?(while ,do while ,for)


 

程序源代码:

while:

public class First {public static void main(String[] args) {// TODO Auto-generated method stubdouble a=8;        //2006年的人数double b= 1.25;   //每年增加的百分比为0.25int c=2006;       //开始的年份while(a<=20)     //while的判断条件{a=a*b;       //a每增加一年的人数c++;         //每增加一年的人数,年份加1}System.out.println("到"+c+"年人数达到20万");//输出结果}}



do while:


public class Second {public static void main(String[] args) {// TODO Auto-generated method stubdouble a=8;        //2006年的人数double b= 1.25;   //每年增加的百分比为0.25int c=2006;       //开始的年份do{a=a*b;       //a每增加一年的人数c++;         //每增加一年的人数,年份加1}while(a<=20);System.out.println("到"+c+"年人数达到20万");//输出结果}}





for:

public class Third {public static void main(String[] args) {// TODO Auto-generated method stubdouble a=8;        //2006年的人数double b= 1.25;   //每年增加的百分比为0.25int c=2006;       //开始的年份for(a=8;a<=20;c++)//初始值a=0;判断条件:a<=20;所以c++{a=a*b;        //得到a的值}System.out.println("到"+c+"年人数达到20万");//输出结果}}



分析过程:流程图:

while




do while




for




调试结果测试图:

while



do while





for