Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tricky program

 
Sam PaulD
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of my friends posed me a question i foud it to be bit tricky can any one help me in this

Question goes like this :




the obvious out put is Sam! but wants out put like this "Hai Sam! Bye." without changing the main method can we do this ?
 
Rob Spoor
Sheriff
Pie
Posts: 20380
45
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For executing something before the main method is executed you can use a static initializer block. That still does not help you with the output after the main method's code.

I can cheat however:
 
Sam PaulD
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are missing some part of the code I am getting compilation errors at


can you pl. re check it
 
mahesh kale
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think that code works ine but i did few modifications with it...will post it..as soon as i get my eclipse window out of CTRL ALT DEL
 
Rob Spoor
Sheriff
Pie
Posts: 20380
45
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam PaulD:
I guess you are missing some part of the code I am getting compilation errors at


can you pl. re check it

You'll have to import java.io.PrintStream.
 
Shivit Agarwal
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Rob Prime

Can you please explain the code especially the Print stream ??
 
Rob Spoor
Sheriff
Pie
Posts: 20380
45
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Shivit Agarwal
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ROb Prime.
Thanks a lots mate...
 
Irina Goble
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about just a simple print statement?
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can also stop the main() method from executing with this static initializer.



Too bad the main methods uses the println() method, instead of the print() method. If it just used the print() method, you could've also done this in the static initializer.



Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20380
45
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Irina Goble:
What about just a simple print statement?

It misses the "Bye." part.
 
Irina Goble
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:

It misses the "Bye." part.


Oops, missed it! It will print the " Bye." part if it's called as
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic