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

Thread: Help Neeed

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Help Neeed

    I want to make a program to print a pattern
    can anybody please help me providing code?


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    This is my pattern to print

    *****
    ****
    ***

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    Please do not post duplicate threads, especially ones that hijack the threads of other users. That's extremely rude. How would you like it if somebody now posted their own question as a reply to this thread?

    Nobody is going to write the code for you. That's not how this works, at all. What have you tried? Where are you stuck?

    Read the link in my signature on asking questions the smart way. Provide an SSCCE that demonstrates where you're stuck, ask a specific technical question, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    I am extremely sorry i am very new here. thats why the mistake has done


    Quote Originally Posted by KevinWorkman View Post
    Please do not post duplicate threads, especially ones that hijack the threads of other users. That's extremely rude. How would you like it if somebody now posted their own question as a reply to this thread?

    Nobody is going to write the code for you. That's not how this works, at all. What have you tried? Where are you stuck?

    Read the link in my signature on asking questions the smart way. Provide an SSCCE that demonstrates where you're stuck, ask a specific technical question, and we'll go from there.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help Neeed

    Do a search on the forums. This question has been answered several times.
    When you are on a thread, if you scroll down you will see a 'Similar Threads' box which will provide you with more answers.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    import java.io.*;
    public class pattern1
    {
    public static void main (String[] args) throws IOException
    {
    InputStreamReader read = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(read);
    int i,j,n=0,k;
    System.out.print("How many stars you want to print in first row ? ");
    n=Integer.parseInt(in.readLine());
    for (i = 0; i<n; i=i+2)
    {
    for (j=i; j<n;j++)
    System.out.print ("*");
    System.out.println();
    if(i<n)
    System.out.print(" ");
    }
    }
    }
    in the above code i can print 1 space in second line. but i want to print 2 stace in 3rd line and 3 space in 4th line

    output as follows---
    How many stars you want to print in first row ? 7
    *******
    ******
    ****
    **

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

    Default Re: Help Neeed

    Moved to Java Theory & Questions

    arunjib, just to let you know I have deleted many of your other posts which were duplicates and in the incorrect location. As Kevin mentioned, please refrain from doing this and if you have a question, simply start a new thread.

  8. #8
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    Thank u sir. i am sorry for doing that. now my question is posted in this thread. this thread is created by me. hope i shall get this problem solved through this forum.
    regards
    arunjib

    Quote Originally Posted by copeg View Post
    Moved to Java Theory & Questions

    arunjib, just to let you know I have deleted many of your other posts which were duplicates and in the incorrect location. As Kevin mentioned, please refrain from doing this and if you have a question, simply start a new thread.

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    What do you think your code does? There are a few things that simply make no logical sense. For example, why do you have an if statement that checks whether i is less than n? Your for loop already guarantees that that will always evaluate to true.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    I have made a code to print the pattern as

    *****
    ****
    ***

    as follows
    import java.io.*;
    public class pattern1
    {
    public static void main (String[] args) throws IOException
    {
    InputStreamReader read = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(read);
    int i,j,n=0,k;
    System.out.print("How many stars you want to print in first row ? ");
    n=Integer.parseInt(in.readLine());
    for (i = 0; i<n; i=i+2)
    {
    for (j=i; j<n;j++)
    System.out.print ("*");
    System.out.println();
    }
    }
    }

    but in the above code i cannot print 1 leading space in 2nd line and 2 leading space in 3rd line.
    Please help me.

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    I don't see any code that suggests you're attempting to print a space at all.

    Hint: Maybe you should write a method that takes two parameters, a character and an int, that prints out the character that number of times.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    sir i want to print spaces using for loop. but i am unable to do that. as i am not strong on nested for loop. may i get a complete help from this site/thread without thinking more? if so i shall be greatful. if not i just want to quit my question as i am upset on it. if i had much knowledge i must not put a beginner level question. i am sorry if i do anything mistake here in this net.


    Quote Originally Posted by KevinWorkman View Post
    I don't see any code that suggests you're attempting to print a space at all.

    Hint: Maybe you should write a method that takes two parameters, a character and an int, that prints out the character that number of times.

  13. #13
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    Sorry, but programming requires thinking. You aren't just going to get a full solution. That's not how this works. That's not learning- it's cheating.

    If you aren't strong on nested for loops, take my suggestion of writing a method. That way you don't have to deal with nested for loops directly.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #14
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    Do you know A, B, C, D .... Z ? Can you remember how first time you learnt alphabet ? Was you thinking or reading reapedly ? No ! you just taken help from your teacher (or mom or dad). So as i cannot do this i need just a solution not a teacher like you. I really cannot fine anything to do this. Moreover i am not cheating anybody.

    Quote Originally Posted by KevinWorkman View Post
    Sorry, but programming requires thinking. You aren't just going to get a full solution. That's not how this works. That's not learning- it's cheating.

    If you aren't strong on nested for loops, take my suggestion of writing a method. That way you don't have to deal with nested for loops directly.

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    Quote Originally Posted by arunjib View Post
    Do you know A, B, C, D .... Z ? Can you remember how first time you learnt alphabet ? Was you thinking or reading reapedly ? No ! you just taken help from your teacher (or mom or dad). So as i cannot do this i need just a solution not a teacher like you. I really cannot fine anything to do this. Moreover i am not cheating anybody.
    Drop the attitude.

    I have told you what to do, in more than one way. If you don't understand something about it, ask. Have you tried to create a method that prints out a character a certain number of times? If not, then do not complain about your inability to follow instructions. If so, post your attempt and ask a specific question about it.

    Or think about it this way- how would you do this "by hand"? Pretend you have a friend who has no idea how to draw the pattern you need. What steps would you give him, so that he could follow them and accomplish your goal? Make sure each step is very specific and very short, otherwise your friend will become confused. When you have those steps written out, you'll have an algorithm that should be pretty easy to translate into code.

    If I see another negative comment from you, I'm done trying to help you. There are too many other people, who actually want to learn and are willing to follow directions, that I could be helping instead. Nobody is going to simply hand over the code, and if they did, you wouldn't be learning from it anyway.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    Thank you sir,
    I was really depressed on the problem. Atlast i could solve my problem with help of my teacher. Thank you once more for your support. I hope i shall try to read and understand your instructions calmly in future. Please forgive me!

    Quote Originally Posted by KevinWorkman View Post
    Drop the attitude.

    I have told you what to do, in more than one way. If you don't understand something about it, ask. Have you tried to create a method that prints out a character a certain number of times? If not, then do not complain about your inability to follow instructions. If so, post your attempt and ask a specific question about it.

    Or think about it this way- how would you do this "by hand"? Pretend you have a friend who has no idea how to draw the pattern you need. What steps would you give him, so that he could follow them and accomplish your goal? Make sure each step is very specific and very short, otherwise your friend will become confused. When you have those steps written out, you'll have an algorithm that should be pretty easy to translate into code.

    If I see another negative comment from you, I'm done trying to help you. There are too many other people, who actually want to learn and are willing to follow directions, that I could be helping instead. Nobody is going to simply hand over the code, and if they did, you wouldn't be learning from it anyway.

  17. #17
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    It's fine. But you have to understand that we aren't here to simply write code for you- not only is that cheating, but it doesn't help you anyway. Thee process of working through a problem and hitting that "ah-ha!" moment are really important to learn. I don't try to be mean, but we simply cannot give out answers to homework like that.

    I'm glad you eventually got it figured out.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  18. #18
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    Thank you sir for your kind co-operation and giving proper guide. I i get permission i want to start another problem here. Can I?
    Quote Originally Posted by KevinWorkman View Post
    It's fine. But you have to understand that we aren't here to simply write code for you- not only is that cheating, but it doesn't help you anyway. Thee process of working through a problem and hitting that "ah-ha!" moment are really important to learn. I don't try to be mean, but we simply cannot give out answers to homework like that.

    I'm glad you eventually got it figured out.

  19. #19
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help Neeed

    Huh? You don't need to ask permission. It's a public forum. Post away. But keep in mind everything I said- ask a specific question, show your work (in SSCCE form), and be ready to actually learn and work.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  20. The Following User Says Thank You to KevinWorkman For This Useful Post:

    arunjib (March 10th, 2011)

  21. #20
    Junior Member
    Join Date
    Mar 2011
    Location
    West Bengal, India
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help Neeed

    thanks.......................