Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Chisisi Massri   on Sep 24 In Java Category.

  
Question Answered By: Ralph Murray   on Sep 24

Unfortunately it's not as easy in Java as in C/C++. In C and C++ the
function printf() always returns an integer indicating how many
characters have been printed; System.out.print() and related functions
in Java are void functions, so they can't be used in an if statement
like mentioned by Anurag.

I think it might be able by using some Stream output function instead
of System.out.println(), but you should check the Javadoc of streams
whether this is possible or not. To be honest I'm not in the mood to
look this up myself, I'm on vacation. ;-)

The C version might be this one, I haven't tried it yet:

int main( int argc, char * argv [])
{ if (printf( "Hello world!\n"))
{}
}

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 


Tagged: