aspose file tools*
The moose likes Beginning Java and the fly likes system.out.print with ternary operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "system.out.print with ternary operator" Watch "system.out.print with ternary operator" New topic
Author

system.out.print with ternary operator

senthil doraiswamy
Greenhorn

Joined: Feb 14, 2002
Posts: 9
I would like to know why second argument in System.out.print ( args[i] ) is not printed when i = 0.

class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++)
System.out.print(i == 0 ? args[i] : " " + args[i]);
System.out.println();
}




--- sen.
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Read i == 0 ? args[i] : " " + args[i] as follows

More on the terenary operator - http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.25
[ June 19, 2008: Message edited by: Ashish Hareet ]
senthil doraiswamy
Greenhorn

Joined: Feb 14, 2002
Posts: 9
Ashish, thank you.
 
 
subject: system.out.print with ternary operator