Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 12th, 2007, 6:51 PM   #11
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Your solution Arevos worked ... and for that I would like to give you a kiss. However, since I'm not gay I will just say thank you and have a nice day.

Also thank you everyone else who has put time into this.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Jan 12th, 2007, 7:06 PM   #12
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 909
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
I would be more than happy if someone could explain to me why that code compiles under Java 5. According to Sun's documentation, the following is the correct way to call printf:

Object[] args = { new String("Java is object oriented.") };
System.out.printf("|%s|%n", args);
titaniumdecoy is offline   Reply With Quote
Old Jan 12th, 2007, 8:16 PM   #13
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Eric the Red
Your solution Arevos worked
You're welcome. It's nice to know that a year spent working with Eclipse still has it's uses

Quote:
Originally Posted by titaniumdecoy View Post
I would be more than happy if someone could explain to me why that code compiles under Java 5. According to Sun's documentation, the following is the correct way to call printf
Both ways work. Java 5 also introduced varargs, which are denoted by an ellipses (...) after the type. If you look at the type of the function:
public PrintWriter printf(String format, Object... args)
You'll notice that the end argument isn't a normal array. IIRC, you can use it in one of two ways. Like this:
System.out.printf("%s %s", new Object[] { "Hello", "World" });
Or like this:
System.out.printf("%s %s", "Hello", "World");
The two are equivalent; the second form is essentially just syntactic sugar for the first. Incidentally, C# has exactly the same functionality, which behaves in exactly the same way, but uses the keyword "params" instead.

Also, this type of string creation:
new String("Java is object oriented.")
Is almost always wrong and bad. The only time it's of possible use is when dealing with small substrings of large strings. I can go into detail, if anyone's really interested in the strange little nooks and crannies of Java.
Arevos is offline   Reply With Quote
Old Jan 12th, 2007, 8:24 PM   #14
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 909
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Thanks for the explanation, Arevos. I had never heard of varargs before (in Java, that is).
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
500 Ways to Program Numbers 1 Through 10! Sane Coder's Corner Lounge 637 Jan 5th, 2008 11:15 PM
Custom Hashing Algorithms Sane C 21 Oct 16th, 2006 10:05 PM
complete newbie question melee28 C 36 Sep 11th, 2005 7:48 AM
problem with this calculator program designXperts.net Java 2 May 23rd, 2005 7:14 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC