I'm writing a program that determines the population of the world between years 1975 to 2006. I found an equation for the world pop and i put it in my code, but i keep getting a '.class' expected. Can anyone help???

--Cassie

P.S: The error is where pop is defined. (pop = 4 * double pow(e, t); )

import TerminalIO.KeyboardReader;
 
 class WorldPop {
 	
 	public static void main(String args[]) {
 		
 		KeyboardReader reader = new KeyboardReader();
 		
 		char answer;
 		int year;
 		double pop;
 		double e = 2.71828183;
 		double t = 0.019*(year - 1975);
 		
		System.out.println("This program computes the World Population from 1975 to 2006.");
		System.out.println("Would you like to run this program?");
		
		answer = reader.readChar();
			
 		while(answer == 'y') {
 			
 		System.out.println("Enter the year."); 
 	    
 	    	year = reader.readInt();
 	    	
 	    	pop = 4 * double pow(e, t);
 	    	
 	    	System.out.println("The population in " + year + " is " + pop);
 	    	
 	    	System.out.println("Do you wish to re-run this program?");
 		
 			answer = reader.readChar();
 		
 		}    
 	    	 	
 	}
 }

Recommended Answers

All 5 Replies

On the line

pop = 4 * double pow(e, t);

is the class name that the method "pow" belongs to double or Double, and isn't there a character missing between those two words (yes, there is a character missing)?

On the line

pop = 4 * double pow(e, t);

is the class name that the method "pow" belongs to double or Double, and isn't there a character missing between those two words (yes, there is a character missing)?

I am soooo confused. What character is missing?

ooooh!! No, pow is so that e is to the power of t. I found that in a java book, and used it. Should i just change it to something else??

Statement is written incorrectly,
pop = 4 * double pow(e, t);

pow is a static method of java.lang.Math class and you have to write the statement as follows:

pop = 4 * Math.pow(e,t);

Statement is written incorrectly,
pop = 4 * double pow(e, t);

pow is a static method of java.lang.Math class and you have to write the statement as follows:

pop = 4 * Math.pow(e,t);

yeah, I realized that this morning, and I was going to post that I solved the problem, but DaniWeb wasn't opening on my computer. But thank you soooooo much. It works now =D yay!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.