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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Doing my head in! "for" loops

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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)
          {
              //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
    Last edited by helloworld922; May 24th, 2013 at 02:39 PM. Reason: please use [code] tags


  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default 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. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Doing my head in! "for" loops

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

Similar Threads

  1. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  2. "Program execution skips the "if" statement"!
    By antony1925 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2012, 07:15 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM

Tags for this Thread