174k views
5 votes
Write a program that prints the following line of output 1000 times:

All work and no play makes Jack a dull boy.
You should not write a program that uses 1000 lines of source code; use methods to shorten the program.
(Hint: use methods to shorten the program). Each print statement should only have one line of "All work and no play makes Jack a dull boy". What is the shortest program you can write that will produce the 1000 lines of output, using only the material?
White spaces will be ignored (empty lines, (. ). class header, method headers, etc)
AllWorkNoPlay: Using static methods to shorten the program (no loops allowed)
AllWorkNoPlay

User Bwegs
by
4.6k points

1 Answer

5 votes

Answer and Explanation:

Using javascript:

var play;

function AllWorkNoPlay(){

Console.log("All work and no play makes Jack a dull boy");

play++

If(play<=1000){

AllWorkNoPlay()

}

else(

return;

)

}

AllWorkNoPlay()

From the above we have defined a function that uses recursive function to print "All work and no play makes Jack a dull boy" to the console 1000 times and not more than that. We have called the function after that.

User Miguelr
by
6.0k points