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

Thread: What is wrong with my spaces?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is wrong with my spaces?

                    for(int i = 4; i >= 1; i--){
     
    			for(int numbers = 1; numbers <= i; numbers++){
     
    				for(int space = 4; space > i; space--){
     
    					if(numbers > 1)continue;
    					if(space > i)System.out.print(" ");
     
    				}
     
    				System.out.print(numbers + " ");
    			}
    			System.out.println();
    		}

    It prints out like this
    1  2  3  4  
     1  2  3  
      1  2  
       1

    But I want the spaces to be like this
    1 2 3 4
      1 2 3
        1 2
          1


  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong with my spaces?

    Any suggestions on what is flawed in my code?

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: What is wrong with my spaces?

    Add more spaces in front of the numbers...

  4. #4
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: What is wrong with my spaces?

    To be honest you're biggest problem is that in one minute you expected an answer and you spent a full 15 seconds posting your code instead of a SSCCE.

    Change this line to remove the space and see what happens:

    System.out.print(numbers + " ");
    Need Java help? Check out the HotJoe Java Help forums!

  5. The Following User Says Thank You to stdunbar For This Useful Post:

    copeg (May 25th, 2012)

  6. #5
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong with my spaces?

    Thanks for the worthless suggestion. I figured it out either way. And it had nothing to do with removing that line.

  7. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: What is wrong with my spaces?

    Quote Originally Posted by wolf_fcknHaley33 View Post
    Thanks for the worthless suggestion. I figured it out either way. And it had nothing to do with removing that line.
    Nice way to thank someone trying to help you in their free, unpaid time. Responses like that don't win you any favors, and believe it or not do affect your chances of using these forums in a productive way in the future, and not following up your question with a statement about how you solved it even more so.

Similar Threads

  1. Trying to create Triangles with Characters and Spaces
    By MJtechie12 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 20th, 2011, 04:20 PM
  2. [SOLVED] Replacing dots with spaces
    By dTi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 17th, 2011, 08:53 PM
  3. [SOLVED] Splitting a txt file with multiple spaces
    By macko in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: November 1st, 2011, 01:03 PM
  4. Cant get spaces
    By Ksmartman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 13th, 2010, 07:06 AM
  5. How to remove the in-between spaces in a String? Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 2
    Last Post: February 4th, 2010, 04:19 PM