For part of my project, I need to write a piece of code that will perform a task (beeping) once per second for ten seconds. I found this code online and tried to modify it to fit my needs, but I couldn't seem to get it. This code doesn't beep, it just prints "doing" every second, but that's not important - I can change that later. I just need help in figuring out how to make it print "doing" only ten times, and not keep going until the program is manually stopped. Any help is appreciated. :)
import java.util.Timer;
import java.util.TimerTask;
public class AnnoyingBeep {
public static void main(String[] argv) throws Exception {
int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
System.out.println("doing");
}
}, delay, period);
}
}
Note/Disclaimer: The code isn't mine - I copied it off a website somewhere. I don't know which website it was or who wrote it, but I have no intention of using this code to make money or redistribute, or of turning it in for school credit. //import legalese;