Is there any key-word that multiplies the message or do i have to write System.out.println("message") five times?
Thanks.
Printable View
Is there any key-word that multiplies the message or do i have to write System.out.println("message") five times?
Thanks.
I think that you're stuck with using a for loop. Unless I'm mistaken, I don't think that core Java has that bit of syntactic sugar.
You could loop over the Sysout call 5 times rather than writing the line 5 times.
ETA: Ninja'd by a matter of seconds!
I don't think it's about loops.I'm just starting to learn Java and the exercise is from the chapter 1 of a book(Introduction to Java Programming-Liang).In chapter 1 I didn't read about loops.
here's the text: 'Write a program that displays Welcome to Java 5 times'
tought so,but I also thought it was some trick I didnt know.
tnx.
Other languages can 'multiply' a String by an int (Python comes to mind) but Java is not one of them; if you don't know how to implement a (simple) loop, you either have to print your message five times (your editor can do the boring job), or you have to apply a little trick:
kind regards,Code:String message= <your message>;
String message2= message+message;
String message4= message2+message2;
String message5= message+message4;
Jos