Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default need help with a for loop

    taking a seminar on java. was asked to work on building a program that can convert fahrenheit to kelvin. Need to create a for loop that spits out the value of kelvin for every degree increase from 32 degrees fahrenheit to 100 degrees fahrenheit. totally stumped. any tutors out there can help guide?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: need help with a for loop

    Quote Originally Posted by staticprofessional View Post
    taking a seminar on java. was asked to work on building a program that can convert fahrenheit to kelvin. Need to create a for loop that spits out the value of kelvin for every degree increase from 32 degrees fahrenheit to 100 degrees fahrenheit. totally stumped. any tutors out there can help guide?
    The code for the loop is simple:
    Java Code:
    for (double fahrenheit= 32; fahrenheit <= 100; fahrenheit++)
       // convert fahrenheit to celcius and print the result here ...
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: need help with a for loop

    @OP: please don't send me a PM w.r.t. your question; post follow up replies in the forum and maybe somebody else can be of help too.

    kind regards,

    Jos

    ps. this was the code you posted in your PM:
    Java Code:
    public class Converter 
    {
    public static void main(String[] args)
    {
    for (double fahrenheit= 32; fahrenheit <= 100; fahrenheit++)
    double celsius = 5/9.0*(farenheit-32);
    double kelvin = celsius + 273.16;
    System.out.println("The Kelvin equivalent of " fahrenheit + " degrees Fahrenheit is:" + kelvin);
    }
    }
    count your curly brackets.
    Last edited by JosAH; 07-07-2014 at 10:41 AM.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: need help with a for loop

    sorry about that. but yea, still struggling with it.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: need help with a for loop

    Let me reformat that code, perhaps then you'll see it.

    Java Code:
    public class Converter {
    
      public static void main(String[] args) {
        
        for (double fahrenheit= 32; fahrenheit <= 100; fahrenheit++)
          double celsius = 5/9.0*(farenheit-32);
        
        double kelvin = celsius + 273.16;
        System.out.println("The Kelvin equivalent of " fahrenheit + " degrees Fahrenheit is:" + kelvin);
      }
    }
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Simple loop within a loop not working.
    By supremegrandruler in forum New To Java
    Replies: 3
    Last Post: 03-21-2014, 10:27 AM
  2. while loop not checking if it can loop
    By totalspelnerd in forum New To Java
    Replies: 11
    Last Post: 06-18-2013, 06:01 PM
  3. Replies: 2
    Last Post: 11-07-2011, 03:25 AM
  4. Replies: 1
    Last Post: 10-01-2011, 03:12 AM
  5. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •