aspose file tools*
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
Author

Clearing a system?

Brandon Choate
Greenhorn

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39


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.

Henry


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

Joined: Oct 13, 2005
Posts: 36514
    
  16
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.
 
Consider Paul's rocket mass heater.
 
subject: Clearing a system?
 
Similar Threads
Attempting Polymorphism...unsuccessfully
weird hasNextDouble behavior.
geometry in java
I need some help with a JUnit test.
Help with Value Returning Methods