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

Thread: Setting up table and converting kilograms to pounds

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Setting up table and converting kilograms to pounds

    Hello all again,

    I have a problem with my code can't seem to figure out the problem. Some help would be greatly appreciated.

    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
        System.out.println("Kilo       Pounds ");
        for(int k = 1; k <= 200; k+ = 5) {
            System.out.println(" + k + "      " + k*2.2 + ");
        }
     
        }
     
    }


    --- Update ---

    I noticed a small problem. I created a local variable int k; before the for loop. But it is still saying illegal start of an expression


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,739
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Setting up table and converting kilograms to pounds

    Please post the entire error message as it appears on your end, copied and pasted. Sometimes important details are lost in the poster's translation.

    On line 9, there is a space between '+' and '='. The operator is '+=' together.

    On line 10, inside the println() method, there are multiple errors. Items between quotes are interpreted as Strings and must be concatenated with the '+' symbol. I'm not sure exactly what you're trying to do in that line, but I'm guessing it might be something like:

    System.out.println(" " + k + " " + ( k * 2.2 ) );

    Try that line, notice how it prints, and notice the difference between it and your statement. Ask if you have questions.

  3. #3
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Setting up table and converting kilograms to pounds

    Greg got it all haha but just as an esthetic advice you should use "\t" which inserts tab spaces and makes it look better instead of actually adding the spaces for divisions manually.

    like this:
    System.out.println("Kilo\tPounds");
     
    System.out.println(k + "\t\t" + k * 2.2);

    in the second println added two tab spaces to align it properly with the kilo and pounds row xD
    it looks more presentable but it is up to each's preference :p

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,511
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Setting up table and converting kilograms to pounds

    Even better for formatting table like data is printf method.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Setting up table and converting kilograms to pounds

    Thanks for the help again.

Similar Threads

  1. setting up the JAVA EE environment
    By shreerangpande in forum Java Servlet
    Replies: 4
    Last Post: May 14th, 2014, 04:16 PM
  2. Need help with Enums and setting costs
    By Charlie.beat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2012, 02:44 PM
  3. Setting Up a map using jstl
    By kunal_00731 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: September 25th, 2011, 03:00 PM
  4. JFileChooser setting directory
    By fox in forum AWT / Java Swing
    Replies: 2
    Last Post: February 18th, 2011, 10:58 AM
  5. Setting up, using DataSources
    By jasonm in forum JDBC & Databases
    Replies: 1
    Last Post: March 4th, 2010, 09:37 PM