Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with homework very new to java  RSS feed

 
Lynn Cross
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help with writing a program that prints a 4 x 4 square using astericks. this is what I have but it is not working. I know something is missing, help please. I've only had java 1 week, online.

square.java
{
public class square
public static void main (String args()

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

 
Iqbal Ali
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1- Remove the filename "square.java" (if it is written in your code, I mean).

2- Take the opening curly bracket at the end of your class definition.

Hope that works for you..
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Lynn!

Perhaps you'll gather an idea for what to do given the following example program that simply prints "Hello World!" to the system console.Also, you might like to have the following list of free on-line Java tutorials and books that I have found useful handy:
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials
  • Interactive Programming In Java by Lynn Andrea Stein
  • Bruce Eckel's Thinking In Java
  • JavaRanch's own Campfire Stories
  • Allen B. Downey's How To Think Like A Computer Scientist
  •  
    Vicken Karaoghlanian
    Ranch Hand
    Posts: 522
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you want to learn more consider the following
    1) Write your code using loops
    2) Printing out filled/not filled square.
     
    Tim Raczek
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I got this thread looking for "print" and I'd like to go one further than displaying "Hello World"

    As System.out.println("Hello World!") will display "Hello World" to the screen, I want to print out the words, "Hello World", to paper. I thought
    My intention is that I'd like to print results of some SQL work being done. I have a java program that I can use to enter SQL statements and work with a database (MySQL) I created. I can also do this entering of statements through MySQL itself.

    I have a link to a Java World article, 5 parts, on Printing in Java http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html and thought this is what I need, but it's not as simple as I thought. I'm not looking to print a book, I just want a hard copy of some of my data. Is this java article what I need o is there a much more simple solution?

    Thank you for any help.
     
    Michael Dunn
    Ranch Hand
    Posts: 4632
     
    Tim Raczek
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the links.

    From everything I've read, it doesn't appear that I can print any SQL results directly to paper, I need to put them somewhere first, either in a java GUI or a file and from there, print.

    I like the idea of PrintUtilities.printComponent(componentToBePrinted) whenever you want to print the contents of a window. Just that I need a componentToBePrinted. That's what makes me think I need to send results to a jframe.

    Am I right with this, that I can't send results put to a DOS screen to the printer? A DOS screen is not a component.
    [ September 05, 2004: Message edited by: Tim Raczek ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!