-4

I want to make a utility program which shows the date, hour ... :

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class hh {
    public static void main(String[] args) {
        Scanner mihai = new Scanner (System.in);
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("dd.MM.yyyy");
        Date hNow = new Date( );
        SimpleDateFormat ht = new SimpleDateFormat ("kk:mm");
        String lol;
        lol = mihai.nextLine();
        switch (lol) {
            case "Date":  
                lol = ft.format(dNow);
                break;
            case "Hour":  
                lol = ht.format(hNow);
                break;
            case "?": 
                lol = "2. Hour";
                System.out.println("Supported functions:");
                System.out.println("1. Date");
                break;
            default: 
                lol = "Type ? for help";
                break;
        }
    }
}

But I use eclipse neon for editing the code, but after 1 use the program is terminated. I want to: When the program is at final auto restart it.(go to line 8).

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Mikey
  • 29
  • 2
  • 2
  • 4

1 Answers1

2

To repeat something you can use a while-loop.

The easiest method to perfom this, is to put your code between while(true). The while loop is looping the code as long as the condition between the brackets is true. If you write while(true) the condition is always true. That is why it is always repeating your code immediately.

while(true){
    //your code
}

More information at: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

Black Phantom
  • 257
  • 2
  • 10