1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

clear console

Discussion in 'Java' started by adroit89, Feb 11, 2008.

  1. adroit89

    adroit89 New Member

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

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

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

    In Java, it can be done in 2 ways :

    (1) STUPID WAY
    Code:
    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:
    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();
            }
    }
     
  3. devunion

    devunion New Member

    I think that it has sense to combine these two methods.
     
  4. onzo

    onzo New Member

    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
     
  5. teebs

    teebs New Member

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

Share This Page