i need to write a code in perl/java which prints a name 100 times in a1 second [closed]
Ca开发者_JAVA技巧n any one please help me to write a code in perl/java that prints a name 100 times in 1 second.
Be careful what you wish for.
use Time::HiRes qw(sleep);
my $how_many_times = 100;
my $how_long = 1; # second
my $name = 'amit';
for (1..$how_many_times) {
sleep $how_long / $how_many_times;
print $name;
}
for loop can be executed in less than 1 second to print a name 100 times in java/perl on a good machine.
I suppose this is the simplest way (but maybe not enough):
String name = "name";
try {
for (int i = 0; i < 100; i++) {
System.out.println(name);
wait(10);
}
} catch (InterruptedException ex) {
ex.printStackTrace(System.err);
}
UPDATE: Better, use Timer
精彩评论