population problem plz help me befor 16 March 2011 !!

population problem plz help me befor 16 March 2011 !!

the Q is : How can i count how many years it will take for the population of a town to go over 30.000 .. consider that it Increases 10% every year ?? And this is my code & i don't where is the mistake ?? Note : i have to use while or do while only ..

import java.util.Scanner; public class popu { public static void main (String [] args ) { int countYear = 1; int popu = 0; double popuCount = popu + ( popu * 0.1);

System.out.println("pleas enter population :" );
Scanner keyboard  = new Scanner (System.in);
popu = keyboard.nextInt();

while     ( popu < 30000);{

System.out.println( popuCount);
countYear++;
//System.out.println("huge people !!");

}

System.out.println(); System.out.println("thx");

}

}

View Answers

March 15, 2011 at 12:31 AM

Hi, Try this Mate

import java.util.Scanner;

public class popu {

public static void main(String[] args) {
    int countYear = 1;
    int popu = 0;

    System.out.println("pleas enter population :");
    Scanner keyboard = new Scanner(System.in);
    popu = keyboard.nextInt();

    while (popu < 30000) {

        System.out.println(popu);
        popu+=(int)(popu*0.1);
        countYear++;

    }
    System.out.println("No of Years Required for population above 30000 are :"+countYear);
      System.out.println("huge people !!");
}

}

BY NAVDEEP SACHDEVA


March 15, 2011 at 12:51 AM

thx =^.^=









Related Tutorials/Questions & Answers:

Ads