+ 1

Why is this not working? Its java.

public class Program { public static void main(String[] args) { } } public class Clock extends Thread { java.text.DateFormat f = //How to format time for this local java.text.DateFormat.getTimeInstance(java.text.DateFormat.MEDIUM); volatile boolean keepRunning = true; public Clock() { //The constructor setDaemon(true); // Daemon thread: interpreter can exit while it runs start(); // This thread starts itself } public void run() { // body of thread while(keeprunning) { // This thread runs until asked to stop String time = f.format(new java.util.Date()); // Current time System.out.println(time); //Print the time try { Thread.sleep(1000); } catch (InterupptedException e) { } } // Ask the thread to stop running public void pleaseStop() { keepRunning = false; } }

2nd Nov 2018, 11:22 PM
SarahDiamondFox
SarahDiamondFox - avatar
4 Réponses
+ 1
There are a number of issues. for starters, the first 7 lines of code are not for this, start by erasing those. while(keeprunning) should be while(keepRunning) ... Capitalization counts. Your final method pleaseStop() is located inside of your run() method. These are the first problems, I dont have time to go deeper into the code, but start with these and go from there
3rd Nov 2018, 12:00 AM
LordHill
LordHill - avatar
+ 1
oh
3rd Nov 2018, 1:46 AM
SarahDiamondFox
SarahDiamondFox - avatar
0
why did you close the Program class and the main method ?
3rd Nov 2018, 10:53 PM
Robert Iticovici
Robert Iticovici - avatar
0
idk, i was kind of winging it, idrk what im doing lol
4th Nov 2018, 2:33 AM
SarahDiamondFox
SarahDiamondFox - avatar