Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default Loop Help Please

    For comp sci class, we have to make a program. For one part of the program it requires you use "*", to make the y-axis of a graph. The teacher wrote on the board how to do it, but I can't remember what he did. So for that part of the program, you have to use loops to make it. I want the code to do this.
    Ex:
    *
    *
    *
    *
    *
    *
    *

    // The "Lol" class.
    import java.awt.*;
    import hsa.Console;

    public class Lol
    {
    static Console c; // The output console

    public static void main (String[] args)
    {
    c = new Console ();
    for (int k=1; k<10; k++)
    {c.setCursor (10-k,0);
    c.println ("*");
    }
    // Place your program here. 'c' is the output console
    } // main method
    } // Lol class







    This is what I tried, but when I run it nothing happens. The screen is just blank. So I just want to know what I have to fix to make the loop work. The loop has to make a certain amount "*".

    Please and thank you.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    What does the Console class from the hsa package do that is different from the Console class in the io package?
    Why are you using that class vs one from the JDK?

    To see something on the screen, use: System.out.println("*");

  3. #3
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    I use it because that's what our teacher taught us to do.
    Can someone help me please?
    Last edited by JavaAssistance; 09-26-2010 at 09:28 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    Hard to tell what is wrong when you are using a class and its methods that are not part of the JDK and are unknown to the rest of us.

    What do you see if you use this: System.out.println("*");

  5. #5
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    When I run, the word "system" gets highlighted and it says "there was 1 error".

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    Java is case sensitive. Use System vs system

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

  8. #8
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Sorry if that wasn't allowed. I posted on 2 sites since I would of have more chances of being helped out. Sorry if that isn't allowed.

  9. #9
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Java is case sensitive. Use System vs system
    It prints a *
    I just replaced c.println statement with the system.out one, and the program works. But it doesn't up on the console part, it just shows up on the "Standard Input/Output " part.Why is that?
    Last edited by JavaAssistance; 09-26-2010 at 10:02 PM.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    There is no objection to posting on other forums as long as you add links to your posts so anyone can see what answers have been made on the other forums. That can save time and effort if the problem has been solved already.

    It prints a *
    Only one? I would expect it to print 9 in a vertical line. Is that what you requested:
    I want the code to do this.
    Ex:
    *
    *
    *
    *
    *
    *
    *

  11. #11
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Omg yess It works just asked my friend, I added an equal sign to the for loop and it work for (int k=1; k<=10; k++). Thanks for the help.

  12. #12
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    There is no objection to posting on other forums as long as you add links to your posts so anyone can see what answers have been made on the other forums. That can save time and effort if the problem has been solved already.


    Only one? I would expect it to print 9 in a vertical line. Is that what you requested:
    It did print 9 in a vertical line.

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2010, 05:05 PM
  2. do while loop?
    By shroomiin in forum New To Java
    Replies: 2
    Last Post: 11-13-2009, 10:32 AM
  3. For Loop
    By YiBoog in forum New To Java
    Replies: 6
    Last Post: 11-11-2009, 07:53 PM
  4. Loop Help!
    By Keno777 in forum New To Java
    Replies: 3
    Last Post: 11-04-2009, 01:11 AM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 PM

Posting Permissions

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