can any one help me how to clear the console in java??? if u can please provide me the code. Thank you.
[ 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(); } }
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