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: small problem ... I need help

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default small problem ... I need help

    I'm very new to Java and I'm getting really good so far in writing codes but i need help with these programs :


    how can i print these shapes using for loop :

    first shape : (I meant with the numbers to be numbers of spaces )
    1234* // this line has 4 spaces
    123**
    12***
    1****
    *****

    second shape:

    ----*
    ---**
    --*-*
    -*--*
    *---*

    these are dashes not spaces ... how can i print them using for loops


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: small problem ... I need help

    What have you tried so far?

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: small problem ... I need help

    public class Test2
    {
    	public static void main(String args[])
    	{
     
    		int count = 1;
    		int count2 = 1;
     
     
    		for (int i = 5 ; i>= 1; i--)
    		{
    			while(count <= (i-1) )
    			{
    				System.out.print(" ");
    				count++;
    			}
     
     
    				while (count2 <= i-4)
    				{
     
    					System.out.print("*");
                        count2+=1;
    				}
     
     
    				System.out.println();
    				count = 1;
                    count2 = 1;
     
    			}
    			} }

    this is what i tried but it is not working i'd think of it some more but i don't have time I have an exam tommorow and I still have lots of things to study and review and hopefully understand

    I just need a quick solution for these I'm not stupid .. hehehe..
    I just don't have time
    I'll really appreciate it if anyone helped me out with them

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    1
    Thanked 5 Times in 5 Posts

    Default Re: small problem ... I need help

    Hi.The first style Loop will be showed below
    public class LoopPrint{
     
     
    public static void main(String args[]){
       int countspace=4;
       int countstar=1;
    for(int i=0;i<5;i++)
    {
       int j=countspace;
     while(j>0)
       {
          System.out.print(" ");
          j--;
       }
       int m=countstar;
     while(m>0){
          System.out.print("*");
          m--;
       }
       System.out.println("");
       countspace--;
       countstar++;
    }
    }
    }

    If you have other problems ,you can send Email to me!
    Last edited by Freaky Chris; December 4th, 2009 at 11:25 AM.

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

    Ashar (December 4th, 2009)

  6. #5
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: small problem ... I need help

    Welcome lewvan00,

    se [ ] brackets for code tags, also please keep material on the forums for future use and learning resources as apposed to making them private via emails.

    Thanks,
    Chris

  7. The Following User Says Thank You to Freaky Chris For This Useful Post:

    lewvan00 (December 4th, 2009)

Similar Threads

  1. quite small (make the changelog non-static, i.e. load its content from a file)
    By Abdallah in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 30th, 2009, 09:00 PM
  2. Fitting a large primitive into a small reference variable
    By Phobia in forum Java Theory & Questions
    Replies: 15
    Last Post: October 23rd, 2009, 03:10 PM
  3. Small Project Ideas
    By Freaky Chris in forum Project Collaboration
    Replies: 20
    Last Post: August 12th, 2009, 12:49 PM
  4. Replies: 1
    Last Post: May 8th, 2009, 08:55 AM