Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Doing my head in! "for" loops

Hey, i'm stuck on a code. In terms of formatting it is printing out what i need, but the final degree values are displaying all the same. each new 'carbon value' should create a new value for the surface temperature. my equation is correct, but the code to get it to pick up the right carbon value I just cant figure out....

```public class StageFour
{
public static void main(String[] args)
{
//Problem Parameters
final double SOLAR_CONSTANT = 1367.0;
final double ALBEDO = 0.3;
final double STEFANBOLTZMANN = 5.67E-8;

//Declare Variable
double surfaceTemperature;
int number;

//Create a decimal format object
DecimalFormat df = new DecimalFormat("#0.00");

//Equation.
for (number = 280; number <= 400; number += 5)
{
surfaceTemperature = Math.pow((((SOLAR_CONSTANT/4)*(1.0 - ALBEDO))/(STEFANBOLTZMANN*(1.0 - (0.65 + (0.1 + 0.06*Math.log((number)/280)))/2)*(ORBITAL_RADIUS*ORBITAL_RADIUS))), 0.25) - 273.15;
System.out.println("For a Carbon Level of " + number + " the Earth's Surface Temperature is " + (df.format(surfaceTemperature)) + "\u00b0" );
}
}
}```

I should be getting lines printed from 280 to 400 with increments of 5, calculating eachof these numbers into my formula to get the appropriate degrees. on paper the equation works..

I should get something that spits numbers out like
For a Carbon Level of 280 the Earth's Surface Temperature is 13.49°
For a Carbon Level of 285 the Earth's Surface Temperature is 13.55°
For a Carbon Level of 290 the Earth's Surface Temperature is 13.61°
For a Carbon Level of 295 the Earth's Surface Temperature is 13.67° etc

but it just spits out all the same degrees values of 13.49 for each carbon level number.

Is anyway able to point out where I have gone wrong in my coding? I cant find any examples to help me out..

Cheers guys

2. ## Re: Doing my head in! "for" loops

Math.log((double)(number)/280)
Got it?)
Int/Int = Int and not Double

3. ## The Following User Says Thank You to angstrem For This Useful Post:

jess91 (May 24th, 2013)

4. ## Re: Doing my head in! "for" loops

Man I was racking my brain. Cheers, that worked
So Happy, Thankyou!!!!