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 2 of 2

Thread: I am having an issue with my code

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I am having an issue with my code

    My code works, but it lists each answer 10 times and I cannot figure why. My code is listed below, also are there any hints to make on 2 places after the decimal appear?

    public class Test1957 {
    // Main Method
    public static void main(String[] args) {

    System.out.println("Feet\t\t\tMeter\t\t\t\tMeter\t \t\tFoot");
    for (double footNumber = 1; footNumber <= 10; footNumber++)
    for (double meterNumber = 20; meterNumber <= 65; meterNumber += 5) {
    System.out.println(footNumber + "\t\t\t" + footToMeter(footNumber)
    + "\t\t\t\t" + meterNumber + "\t\t\t" + meterToFoot(meterNumber));
    }
    }
    public static double footToMeter(double footNumber) {
    double meters;
    meters = 0.305 * footNumber;
    return meters;
    }
    public static double meterToFoot(double meterNumber) {
    double feet;
    feet = meterNumber/0.305;
    return feet;
    }
    }


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: I am having an issue with my code

    Quote Originally Posted by gmamagoodwin View Post
    My code works, but it lists each answer 10 times and I cannot figure why.
    This line: for (double footNumber = 1; footNumber <= 10; footNumber++)


    Quote Originally Posted by gmamagoodwin View Post
    also are there any hints to make on 2 places after the decimal appear?
    Use DecimalFormat class or use System.out.printf() method.

Similar Threads

  1. not sure what the issue is here
    By Tfence in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 28th, 2011, 01:18 AM
  2. code issue, should be silple been working on it for four hours
    By Custermd in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 30th, 2011, 01:19 PM
  3. Beginner trying to write Java code, has issue w/ printing result and 2 decimals
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2011, 11:11 AM
  4. Issue with code. Does not detect duplicate names in file
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2011, 01:13 AM
  5. i do not know how to solve this issue
    By javastupi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 20th, 2010, 07:28 PM