Results 1 to 13 of 13
  1. #1
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Help (Java Eclipse loop using inputted number)

    I've tried EVERYTHING THAT I KNOW! I was suppose to make a code that will create a Triangle depending on your inputted number, for example if you put 5 it will show:

    *
    **
    ***
    ****
    ***** - 5
    ******
    *****
    ****
    ***
    **
    *

    or 8:

    *
    **
    ***
    ****
    *****
    ******
    *******
    ******** - 8
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    I don't know but as you see on the output I showed you, there's wrong with the middle right, when that was supposed to be the number you putted:

    *
    **
    ***
    ****
    ***** - 5
    ****
    ***
    **
    *

    But anyways, please show me how its done! And by the way the output I showed was really supposed to be an opposite direction, you can see it in my code when you run it.

    import java.util.*;
    public class Loopcrap
    {
    public static void main(String [] args)
    {
    int ctr1, ctr2, ctr3;
    for(ctr1=0;ctr1<=5;ctr1++){
    for(ctr3=4;ctr3>=ctr1;ctr3--){
    System.out.print(" ");
    }
    for(ctr2=0;ctr2<=ctr1;ctr2++){
    System.out.print("*");
    }
    System.out.println("");
    }

    for(ctr1=4;ctr1>=0;ctr1--){
    for(ctr3=4; ctr3>=ctr1; ctr3--){
    System.out.print(" ");
    }
    for(ctr2=0;ctr2<=ctr1;ctr2++){
    System.out.print("*");
    }
    System.out.println("");
    }

    }
    }
    Last edited by micolord; 09-07-2011 at 04:09 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by micolord View Post
    But anyways, please show me how its done!
    That's not how it works here as this is not a service to provide you with your homework solutions.

    I suggest that you break down the big task into small tasks and try to solve each small task one at a time. If you get stuck at a step, come back with your code and your question.

    By the way, your problem has nothing to do with Eclipse and all to do with Java. I'm moving this to the New To Java section.

  3. #3
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by Fubarable View Post
    That's not how it works here as this is not a service to provide you with your homework solutions.

    I suggest that you break down the big task into small tasks and try to solve each small task one at a time. If you get stuck at a step, come back with your code and your question.

    By the way, your problem has nothing to do with Eclipse and all to do with Java. I'm moving this to the New To Java section.
    This was not a HOMEWORK! I'm just having fun with it, I tried adding Scanner in it but it keeps giving me ERRORS... Wait I'll post the errors and the fail code I tried.

  4. #4
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    Here's the code:

    import java.util.*;
    public class Loopcrapp
    {
    public static void main(String [] args)
    {
    int ctr1, ctr2, ctr3;
    Scanner Input = new Scanner(System.in);
    for(ctr1 = Input.nextInt();ctr1<=5;ctr1++){
    for(ctr3=4;ctr3>=ctr1;ctr3--){
    System.out.print(" ");
    }
    for(ctr2=0;ctr2<=ctr1;ctr2++){
    System.out.print("*");
    }
    System.out.println("");
    }
    }
    }

    It inputs a five *****, which was supposed to be:

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

    Any idea please?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help (Java Eclipse loop using inputted number)

    You'll want to nest a for loop inside of another for loop. If you figure out the logic on paper, you'll be able to figure the logic in Java. Keep experimenting with your loops and keep testing your code as that's the fun of programming -- watching the fruits of your logic take shape before your eyes.

  6. #6
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by Fubarable View Post
    You'll want to nest a for loop inside of another for loop. If you figure out the logic on paper, you'll be able to figure the logic in Java. Keep experimenting with your loops and keep testing your code as that's the fun of programming -- watching the fruits of your logic take shape before your eyes.
    Hints please? My heads are gonna blow up sooner.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by micolord View Post
    Hints please? My heads are gonna blow up sooner.
    I gave a hint: use two for loops, one nested inside of the other.

    And get used to the increased intracranial pressure. If you're going to be doing a lot of programming, you're going to be experiencing this frequently.

  8. #8
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    "use two for loops, one nested inside of the other."

    ARRRRRRRRRRRRRRRRRRRRRRRRRRRRRRGH.
    Last edited by micolord; 09-07-2011 at 04:14 PM.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by micolord View Post
    a little hint will totally help me.
    U.s.e.
    T.w.o.
    F.o.r.
    L.o.o.p.s.,

    O.n.e
    N.e.s.t.e.d.
    I.n.
    T.h.e.
    O.t.h.e.r.

    Again, just try, try, try. You don't know how lucky you are to have your very own computer lab on your desktop, one that will allow you to experiment and play with code to your heart's content. Why when I was a youngster learning to program...
    Last edited by Fubarable; 09-07-2011 at 04:13 PM.

  10. #10
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    Quote Originally Posted by Fubarable View Post
    U.s.e.
    T.w.o.
    F.o.r.
    L.o.o.p.s.,

    O.n.e
    N.e.s.t.e.d.
    I.n.
    T.h.e.
    O.t.h.e.r.

    Again, just try, try, try. You don't know how lucky you are to have your very own computer lab on your desktop, one that will allow you to experiment and play with code to your heart's content. Why when I was a youngster learning to program...
    It is very tough on me, I'm using a notepad, I don't have any Java Eclipse compiler, I'm using JDK with a notepad, and it is fricking hard but still I'm experimenting as we speak.
    Last edited by micolord; 09-07-2011 at 04:20 PM.

  11. #11
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    I come up with this:

    import java.util.*;
    public class Loopcrapp
    {
    public static void main(String [] args)
    {
    double ctr1, ctr2, ctr3;
    Scanner Input = new Scanner(System.in);
    ctr1 = Input.nextIn();
    for(ctr1<=5;ctr1++){
    for(ctr3=4;ctr3>=ctr1;ctr3--){
    System.out.print(" ");
    }
    for(ctr2=0;ctr2<=ctr1;ctr2++){
    System.out.print("*");
    }
    System.out.println("");
    }
    }
    }

    I'm trying to make an limitation so that it wont end up on a infinite loop but it keeps giving me this error, kindly please tell me what should I do to correct this error:
    C:\> Javac Loopcrapp.java
    Loopcrapp.Java:9: not a statement
    for(ctr1<=50;ctr++){

    The one which is being pointed was: "<" of for(ctr1<=50;ctr++){
    Last edited by micolord; 09-07-2011 at 04:47 PM.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help (Java Eclipse loop using inputted number)

    That's not how you make a for loop. Please check out the tutorial here: for loops

  13. #13
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Help (Java Eclipse loop using inputted number)

    Sorry for replying 5 days late, haha XD I forgot to log back! because I forgot the site and collage really keeps me busy, but I've figured out the codes after 2 and a half hours when I log out here.

    import java.util.*;
    public class Crappyloop
    {
    public static void main(String [] args)
    {
    double ctr1,ctr2,ctr3,ctr4;
    Scanner Input = new Scanner(System.in);
    ctr4 = Input.nextDouble();
    for(ctr1=0;ctr1<ctr4;ctr1++){
    for(ctr3=ctr4;ctr3>=ctr1;ctr3--){
    System.out.print(" ");
    }
    for(ctr2=0;ctr2<=ctr1;ctr2++){
    if(ctr2==0){
    System.out.print("*");
    }
    else{
    System.out.print("**");
    }
    }
    System.out.println("");
    }
    }
    }
    Last edited by micolord; 09-11-2011 at 02:24 PM. Reason: Forgot to add the "}"

Similar Threads

  1. Help (java eclipse loop)
    By micolord in forum Eclipse
    Replies: 2
    Last Post: 09-07-2011, 02:54 PM
  2. Generate Random Number Loop
    By saber210 in forum New To Java
    Replies: 9
    Last Post: 08-12-2011, 05:49 PM
  3. Loop through all letter and number possibilities?
    By Mr.abe90 in forum New To Java
    Replies: 11
    Last Post: 05-29-2011, 08:47 PM
  4. Replies: 4
    Last Post: 10-25-2010, 06:59 AM
  5. Help Creating A Graph From Inputted Data
    By adlb1300 in forum New To Java
    Replies: 6
    Last Post: 10-28-2007, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •