my dog learned polymorphism
The moose likes Beginning Java and the fly likes if / else problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "if / else problem" Watch "if / else problem" New topic
Author

if / else problem

Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 46

I need to print "Hello World" (without quotes) as final output without editing if /else code blocks.
only you are allow to edit is condition of if statement.
How do i get that?
What is the statement that replaces /* edit this condition */ ?



Any ideas???

Thanks


Try and Try one day you can FLY.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

executing both if and else is not possible as far i know. however regarding your result output...


Rohan Deshmkh
Ranch Hand

Joined: Aug 31, 2012
Posts: 127
In java the if condition must have a expression that results into a boolean value.But the closest i got to print hello world was using the foll code:

Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 46

Seetharaman Venkatasamy wrote:executing both if and else is not possible as far i know.


Pretty sure there is a possible way to print Hello World without executing if code block.
I saw one of my friends did that using

or something like that.

anyway thanks for the post!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Oh good grief! I hope you reserve code for showing to friends after you have had too much to drink. If you hand that in in real life, you can expect to have your job terminated PDQ!
Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 46

Campbell Ritchie wrote:Oh good grief! I hope you reserve code for showing to friends after you have had too much to drink. If you hand that in in real life, you can expect to have your job terminated PDQ!


Eureka!!! finally found it.
Here is the code.



output is Hello World
anyway Thanks for the posts guys!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 5783
    
    5

Supun Lakshan Dissanayake wrote:
Campbell Ritchie wrote:Oh good grief! I hope you reserve code for showing to friends after you have had too much to drink. If you hand that in in real life, you can expect to have your job terminated PDQ!


Eureka!!! finally found it.
Here is the code.



output is Hello World
anyway Thanks for the posts guys!


I hope you realize that nobody would ever write real code like this, or if they did, they wouldn't keep their job for long. This kind of code should only be used to test in-depth knowledge or persnickety language details and ability to "think outside the box," and even then, the general opinion is divided about 50/50 on whether it's useful for taht purpose or just plain stupid and pointless.

Also, somebody (don't know if it was you) recently posted the same initial code and asked how to execute both the if block and the else block. Note that this code does not do that, and that it is impossible to do that.

Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 46

Jeff Verdegan wrote:
I hope you realize that nobody would ever write real code like this, or if they did, they wouldn't keep their job for long. This kind of code should only be used to test in-depth knowledge or persnickety language details and ability to "think outside the box," and even then, the general opinion is divided about 50/50 on whether it's useful for taht purpose or just plain stupid and pointless.

Also, somebody (don't know if it was you) recently posted the same initial code and asked how to execute both the if block and the else block. Note that this code does not do that, and that it is impossible to do that.



Thanks for the post.

I'm the topic starter and i'm the one who post the answer also.
I know if i use the output is Bye World.
All i needed was the condition for print hello world (it was a question of a paper).
I think by using is caused to break standards.

Dear Jeff Verdegan, I really appreciate your post for point it. THANK YOU AGAIN !!!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: if / else problem
 
Similar Threads
who can xplain these???
do while loop
System.out.println() question
Clarification about Ternary operator
Hello World!