• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Clearing a system?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 80085
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic