Results 1 to 12 of 12
Thread: Loop Help Please
- 09-26-2010, 07:49 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
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.
- 09-26-2010, 08:20 PM #2
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("*");
- 09-26-2010, 09:24 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
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.
- 09-26-2010, 09:38 PM #4
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("*");
- 09-26-2010, 09:47 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
When I run, the word "system" gets highlighted and it says "there was 1 error".
- 09-26-2010, 09:51 PM #6
Java is case sensitive. Use System vs system
- 09-26-2010, 09:53 PM #7
Cross posted at Loop Help Please - CodeGuru Forums
- 09-26-2010, 09:56 PM #8
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
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.
- 09-26-2010, 09:57 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
- 09-26-2010, 10:01 PM #10
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 prints a *
I want the code to do this.
Ex:
*
*
*
*
*
*
*
- 09-26-2010, 10:04 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
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.
- 09-26-2010, 10:05 PM #12
Member
- Join Date
- Sep 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
How can I rewrite the following while loop using a for loop?
By gt11990 in forum New To JavaReplies: 5Last Post: 04-30-2010, 05:05 PM -
do while loop?
By shroomiin in forum New To JavaReplies: 2Last Post: 11-13-2009, 10:32 AM -
For Loop
By YiBoog in forum New To JavaReplies: 6Last Post: 11-11-2009, 07:53 PM -
Loop Help!
By Keno777 in forum New To JavaReplies: 3Last Post: 11-04-2009, 01:11 AM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks