Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   clear console (http://www.go4expert.com/forums/clear-console-t8756/)

adroit89 11Feb2008 18:08

clear console
 
can any one help me how to clear the console in java???
if u can please provide me the code. :)
Thank you.

SaswatPadhi 15May2009 08:33

Re: clear console
 
[ Nice question, I wonder why is it unanswered yet :crazy: . ]

In Java, it can be done in 2 ways :

(1) STUPID WAY
Code: java

import java.lang.*;

public class Main {
        public void ClearConsole() {
                for (int i = 0; i < 25; i++)
                        System.out.println("\n");
        }

        public static void main(String[] args) {
                new Main().ClearConsole();
          }
}



(2) SMART WAY
Code: java

import java.lang.*;
import java.io.Console;

public class Main {
        public void ClearConsole() {
                Console console = System.console();       
                if (console == null)
                        System.out.println("Couldn't get Console object !");
                console.clear();
        }
   
        public static void main(String[] args) {
                new Main().ClearConsole();
        }
}


devunion 25May2009 21:41

Re: clear console
 
I think that it has sense to combine these two methods.

onzo 31Oct2010 21:11

Re: clear console
 
hi
im trying to make clear (console.clear()) but it says that its not defined for class console
i write the same function u wrote and same imports

teebs 27Feb2012 15:06

Re: clear console
 
Pls all am new here... And am also knew to programming, but i like it. Pls help me


All times are GMT +5.5. The time now is 09:03.