Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clearing a system?

 
Brandon Choate
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21116
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic