Results 1 to 7 of 7
Thread: Displaying a message five times
- 01-13-2012, 03:27 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 3
- Rep Power
- 0
-
Re: Displaying a message five times
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.
- 01-13-2012, 03:33 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Displaying a message five times
You could loop over the Sysout call 5 times rather than writing the line 5 times.
ETA: Ninja'd by a matter of seconds!
- 01-13-2012, 03:38 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 3
- Rep Power
- 0
Re: Displaying a message five times
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'
-
Re: Displaying a message five times
- 01-13-2012, 03:44 PM #6
Member
- Join Date
- Jan 2012
- Posts
- 3
- Rep Power
- 0
Re: Displaying a message five times
tought so,but I also thought it was some trick I didnt know.
tnx.
- 01-13-2012, 07:03 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Displaying a message five times
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,Java Code:String message= <your message>; String message2= message+message; String message4= message2+message2; String message5= message+message4;
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Repeating too many times.
By trishtren in forum New To JavaReplies: 4Last Post: 11-11-2011, 12:20 AM -
Displaying error message if no text found
By jdg951 in forum New To JavaReplies: 3Last Post: 01-17-2011, 10:52 PM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 08:43 PM -
JComboBox displaying variable two times, why?
By ecliptical in forum New To JavaReplies: 6Last Post: 01-24-2010, 06:09 PM -
Urgent-Imp-Displaying message with respect to system time
By garinapavan in forum New To JavaReplies: 1Last Post: 08-03-2007, 02:17 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks