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.

Page 2 of 2 FirstFirst 12
Results 26 to 50 of 50

Thread: Help in making an output for this Graphic (newbie)

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

    Default Re: Help in making an output for this Graphic (newbie)

    What have you tried? Post your code that shows the problem.

  2. #27
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    hey sir Norms,

    the codes you post on post #12 it will shows an output like my 2nd output right?

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

    Default Re: Help in making an output for this Graphic (newbie)

    Compile and execute it and see what is printed.

  4. #29
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    Sir, every false statement will move to the >>>} System.out blah blah right?

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

    Default Re: Help in making an output for this Graphic (newbie)

    There is no boolean variable involved in this logic. It is only loops and math.

  6. #31
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    import java.io.*;
     
    public class Asterisk1
     
    {
          public static void main(String jpg[])
       {
            int n=5;
    	for(int x=5; x<=n; x++)
          {
     
    	  for(int y=1; y<=x; y++)
    	{
     
                System.out.print(" ");
    	}
    	    System.out.println("*");
     
          }
       }
    }
     
     
    the output is:
        *

  7. #32
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    arghhhh.... can't help myself...

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

    Default Re: Help in making an output for this Graphic (newbie)

    Ok. Thats a start. You've printed the first line with some spaces and some *s
    Now add code to print out the next lines.
    You need a loop for the spaces and a loop for the *s

    Can you explain why you start with x=5 in the first for loop?

    It would help if you used variable names and added comments to the code like I did in post#12

  9. #34
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    Quote Originally Posted by Norm View Post
    Ok. Thats a start. You've printed the first line with some spaces and some *s
    Now add code to print out the next lines.
    You need a loop for the spaces and a loop for the *s

    Can you explain why you start with x=5 in the first for loop?

    It would help if you used variable names and added comments to the code like I did in post#12
    i gave a value of 5 to x so if then it goes back to that statement with an increment it will goes false and print an *s because the value of n is no longer equalled or greater than the value of x.

    but i know that's wrong also. because if it goes to System.out.print("*"); it will goes back to the first statement and will tell that every statement is false. And then it will always print *** infintely or what
    Last edited by javarum; June 27th, 2011 at 04:12 PM.

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

    Default Re: Help in making an output for this Graphic (newbie)

    Now add code to print out the next lines: 2 to 5.
    You need a loop for the spaces and a loop for the *s

  11. #36
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    can i do this?


    }

    System.out.print("*");
    System.out.println();
    }

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

    Default Re: Help in making an output for this Graphic (newbie)

    Try it and see what happens.

    What is it you want those two statements to do?
    Can they be merged into a single statement?

  13. #38
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    ehehe. just want to make a new line after printing the last * but it is wrong too. hayyayayay. im near to surrender

  14. #39
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    Sir back to my question cause i didnt understand what youve answered for that. ehehe!

    Is every false statement goes after } ?

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

    Default Re: Help in making an output for this Graphic (newbie)

    There are no true or false statements in this problem. It is done with loops and math.

  16. #41
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    im about to give up... geesh. i know this is too easy but im to newbie for this... not enough time. need to pass this later. ouch. =( and i dont have sleep yet.

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

    Default Re: Help in making an output for this Graphic (newbie)

    Try a very simple exercise:
    Write a loop to print x number of "*" on a line.
    If x is 0 you print none,
    if x is 1 you print 1
    if x is 2 you print 2
    etc

  18. #43
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    cant understand that. pitty on me

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

    Default Re: Help in making an output for this Graphic (newbie)

    Your code shown in the first post does it.

    I guess you should give up for now and try later.

  20. #45
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    cant i have the answer from you? not far from what is my script before? i promise to be better next week. i just need to pass this later on. =(

    i just need the script for this outputs

     
        *
       **
      ***
     ****
    *****
     
    and this one
     
    *****
     ****
      ***
       **
        *
    Last edited by javarum; June 27th, 2011 at 05:35 PM. Reason: for tagging

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

    Default Re: Help in making an output for this Graphic (newbie)

    Come on back when you have had time to write the code.
    See post#42 It has as simple a suggestion as I can make.

  22. #47
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    By the way, SIR Thanks so much your time.

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

    Default Re: Help in making an output for this Graphic (newbie)

    You're welcome.
    Get a good sleep and try again tomorrow.

  24. The Following User Says Thank You to Norm For This Useful Post:

    javarum (June 27th, 2011)

  25. #49
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    there's no tomorrow. hehe! ill fail this assignment. hehe! but ill be better for the next homework. geesh. Thanks Sir! Night!

  26. #50
    Member
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help in making an output for this Graphic (newbie)

    Hi Sir! Can't sleep... already got headache... im about to sleep when i suddenly thought of this.

    import java.io.*;
    public class Asterisk1
     {
          public static void main(String jpg[])
       {
           int n=4;
    	for(int x=1; x<=n; x++)
          {
    	System.out.print(" ");
    	}
    {
    	  for(int y=1; y<=x; y++)
             { 
    	  System.out.print("*");
    	  }
     
    	  System.out.println(); 
     
          }
       }
    }
     
     
     
    error declared on line 12 i think. it says cannot resolve symbol variable x

    am i on my way nearer or further?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Java graphic coordinates out of bounds?
    By jnmcneel in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 24th, 2011, 03:28 PM
  2. how to adjust the size on a graphic component
    By Khoatic in forum AWT / Java Swing
    Replies: 8
    Last Post: November 19th, 2010, 11:28 PM
  3. Graphic angle
    By CoffeeBeans in forum Java Theory & Questions
    Replies: 1
    Last Post: August 22nd, 2010, 11:28 AM
  4. Graphic Environment Abstract Methods
    By striko_514 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 5th, 2010, 01:01 AM
  5. Output problem (newbie)
    By Asido in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 8th, 2010, 12:19 PM