# Doing my head in! "for" loops

• May 24th, 2013, 02:38 PM
jess91
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....

Code java:

```public class StageFour { public static void main(String[] args) { //Adding Carbon //Problem Parameters final double SOLAR_CONSTANT = 1367.0; final double ALBEDO = 0.3; final double STEFANBOLTZMANN = 5.67E-8; final double ORBITAL_RADIUS = 1.0;   //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 :)
• May 24th, 2013, 06:21 PM
angstrem
Re: Doing my head in! "for" loops
Math.log((double)(number)/280)
Got it?)
Int/Int = Int and not Double
• May 24th, 2013, 10:54 PM
jess91
Re: Doing my head in! "for" loops
Man I was racking my brain. Cheers, that worked :)
So Happy, Thankyou!!!!