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

Thread: Printing a Combination

  1. #1
    Member
    Join Date
    Jan 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Printing a Combination

    There are nine empty spaces. Each one of them can be filled with either a 0, 1 or 2. The output should be something like:
    000000000
    000000001
    000000002
    000000010
    000000011
    000000012
    000000020
    000000021
    000000022
    000000100
    000000101
    000000102
    000000110
    000000111
    000000112
    000000120
    000000121
    000000122
    000000200
    000000201
    000000202
    000000210

    Here is the code that I have used:
    public class casesalgo {
    	public static void main(String args[])
    	{
    		for(int a=0;a<3;a++)
    		{
    			for(int b=0;b<3;b++)
    			{
    				for(int c=0;c<3;c++)
    				{
    					for(int d=0;d<3;d++)
    					{
    						for(int e=0;e<3;e++)
    						{
    							for(int f=0;f<3;f++)
    							{
    								for(int g=0;g<3;g++)
    								{
    									for(int h=0;h<3;h++)
    									{
    										for(int i=0;i<3;i++)
    										{
    											System.out.println(""+a+b+c+d+e+f+g+h+i);
    										}
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }

    The problem is that I am getting some blank lines in the output which I do not want. Why are they appearing and how do I get rid of them?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Printing a Combination

    I am getting some blank lines
    Can you post the output from the program that shows the blank lines.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Printing a Combination

    Your code works fine on my PC. The problem might be caused by other reason.

Similar Threads

  1. A deadly combination
    By grNadpa in forum Object Oriented Programming
    Replies: 5
    Last Post: February 25th, 2012, 06:20 PM
  2. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  3. Printing Job
    By qwerty53 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 19th, 2011, 08:34 AM
  4. how to display combination of char and interger
    By bsrk315 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 22nd, 2010, 08:09 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM