clear console

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

  1. adroit89

    adroit89 New Member

    Joined:
    Jan 5, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    [ 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

    Joined:
    Sep 26, 2008
    Messages:
    19
    Likes Received:
    2
    Trophy Points:
    0
    I think that it has sense to combine these two methods.
     
  4. onzo

    onzo New Member

    Joined:
    Oct 31, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Feb 27, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Pls all am new here... And am also knew to programming, but i like it. Pls help me
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice