1

I code a little java programm. Every second I print a value in the console

System.out.println("Test");

I write a command in the moment, if the System.out. loop starts, my command just disappear and goes up with the System.out.println("").

This is my Code:

public class Main{  
public static String s;
public static void main(String[] args) {

    printLogo();

    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {

            Data.cpuUsage = ((OperatingSystemMXBean) ManagementFactory
                                                 .getOperatingSystemMXBean())
                                                 .getSystemCpuLoad() * 100;
            Data.totalMem = ((OperatingSystemMXBean) ManagementFactory
                                                 .getOperatingSystemMXBean())
                                                 .getFreePhysicalMemorySize() / 1000000;

            System.out.println(Data.totalMemory);
        }
    }, 1000, 1000);

    System.out.println("Please type a command:");

Maybe someone can help me? Sorry for my bad English.

azro
  • 53,056
  • 7
  • 34
  • 70
Pascal
  • 31
  • 3

1 Answers1

0

Your issue is that you're printing every second. Whenever the use types something, it'll just be concatenated to the last line printed. If you want to have some form of UI within a terminal, you're going to have to use some type of library (or at least not just System.out.* functions).

Check out Charva.

DavidBittner
  • 515
  • 2
  • 4
  • 15