开发者

i need to write a code in perl/java which prints a name 100 times in a1 second [closed]

开发者 https://www.devze.com 2023-03-08 01:50 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消