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: Tabbing columns

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Tabbing columns

    When trying to tab the following code I keep getting: Syntax error on token "Invalid Character", ( expected, that's the error when mousing over the \t underlined, and the "x" error on the left ( I"m using eclipse) shows :
    Multiple markers at this line
    - Syntax error, insert ")" to complete
    MethodInvocation
    - Syntax error on token "Invalid Character",
    ( expected
    - t cannot be resolved to a variable
    - Syntax error, insert ")" to complete Expression
    - t cannot be resolved to a variable
    - Syntax error on token "Invalid Character",
    ( expected

    // Figure 4.22
     
    public class Powers
    {
    	public static void main ( String[] args )
    	{
    		int n =1;
    		System.out.println("Number\t Squared\t Cubed\t ");
    		while( n <= 10 )
    		{
    			System.out.println( n\t + n*n\t + n*n*n );
    			n++; 
    		}
    	}
     
    }
    When complete I should have a table with the heading, 3 columns with 10 rows basically from 1 to 1000 once I cube 10


  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default Re: Tabbing columns

    None of your "\t"s are in quotes. "\t" only works when it's part of a string. Your println statement should look like this:

    System.out.println( n+"\t" + n*n+"\t" + n*n*n );

  3. The Following 2 Users Say Thank You to dpek For This Useful Post:

    c.P.u1 (January 25th, 2011), SnarkKnuckle (January 24th, 2011)

  4. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Tabbing columns

    Thank you, I know I had tried the quotes, but also looks like I had the "+" signs jacked up too.

  5. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Question Re: Tabbing columns

    I'm not quite sure how you can "jack up" the plus signs, but just "remember that " + " concatenates two strings, in general."

    So, did it work for you? P: (Don't forget to mark the thread as solved if it is)

  6. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Tabbing columns

    The order in which I had them seem to differ from your println code and I wasn't getting good results then, but anyways I changed the code, learned from my mistakes and this one is solved. Thanks

Similar Threads

  1. JList with multiple columns
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: January 27th, 2011, 08:44 AM
  2. [SOLVED] JTables: How do I adjust row order as I drag columns?
    By assel in forum AWT / Java Swing
    Replies: 3
    Last Post: December 7th, 2010, 04:51 PM
  3. Building Table of Specified Rows and Columns
    By wale89 in forum Java Servlet
    Replies: 1
    Last Post: August 3rd, 2010, 08:57 AM
  4. Need a loop for rows and columns
    By Ceasar in forum Loops & Control Statements
    Replies: 8
    Last Post: October 9th, 2009, 05:47 PM