File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Clearing a system? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Clearing a system? " Watch "Clearing a system? " New topic

Clearing a system?

Brandon Choate

Joined: Mar 06, 2009
Posts: 14
Hello again! Just a minor question this time.

I'll go ahead and put up my code:

What I'm trying to do is use System.clear or System.exit at the end of the out.println segment. I'm going to use this as part of a loop and a half code.

Problem is, I don't know how to clear or exit the system. What is the code? System.Clear(); doesn't work!

Second, would this even help with my loop and a half if statement? I'm trying to get it to do a repeat whenever there is nothing put in place for h and such.

I have another program that fills in all the math seen here, that works just fine. No problems there.
Henry Wong

Joined: Sep 28, 2004
Posts: 20535

There is no such a thing as a clear() method in the System class. And the exit() method causes the JVM to exit. Is that what you want?

Regardless, it would be a good idea to look up documentation on the java.lang.System class.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
You should not use System.exit(). There is no need for it.

Whenever the last non-daemon Thread terminates, the JVM will exit automatically. You have a single-threaded application, so you only have one non-daemon Thread, which starts the main method and is called "main". When you reach the end of the loop, you go back to the main method, and when the main method returns (it always "returns" but being "void" returns "nothing"), the main Thread terminates and the JVM closes naturally.

What you actually mean is, how do you exit your loop. Using System.exit() to exit a loop would not be good design. You need some sort of prompt, like this, at the end of your loop:followed by a test whether you have entered "yes", maybe using this method. You can easily work out the rest yourself.
I agree. Here's the link:
subject: Clearing a system?
It's not a secret anymore!