Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners population problem plz help me befor 16 March 2011 !!
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


tofi
population problem plz help me befor 16 March 2011 !!
2 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


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");

}

}


Advertisement
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:
 

 

 

DMCA.com