File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Basic Program Asked in Interview Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Basic Program Asked in Interview" Watch "Basic Program Asked in Interview" New topic
Author

Basic Program Asked in Interview

Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787




I have exercised with above type of programs when I was fresher in Java but at the time of interview after 3 years of Java experience I unable to write complete program of same kind.
I know the logic behind above program. After interview when I came back to home I able to write same kind of program in following manner.



Please note that the above source code completely created by me I didn't refer any site or copy code from others.

Output is as follows



I want to know that whether above approach is correct to write program or any other better way to write same program.
Another thing is why I am not able to complete above program at the time of interview and able to write same after interview.

SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Ninad Kulkarni wrote:
I want to know that whether above approach is correct to write program or any other better way to write same program.


Looks pretty good. I might use more meaningful loop variables than i and j. Maybe row and column or something like that. And I wouldn't use an explicit, platform-specific "\n" end of line. System.out.print(System.getProperty("line.separator") would be a little better. System.out.println() with no args would be better.


Another thing is why I am not able to complete above program at the time of interview and able to write same after interview.


It's impossible for anybody here to give you a solid answer to that. All that's possible are some educated guesses as to what might have been the source of the discrepency. Such as...

Maybe the stress of the interview setting clouded your thinking. Maybe you needed more time than was allotted during the interview. Maybe you had more reference resources available to you at home than you did during the interview. Maybe you didn't get enough sleep the night before. Maybe you had a cold or a hangover. Maybe there was something distracting in the interview setting, like loud noises or an attractive interviewer. Maybe between the interview and when you wrote the code at home, you talked to somebody or saw something online that gave you insight or knowledge that you were lacking during the interview. Maybe you were in a bad mood on the interview day for unrelated reasons, such as problems with your girlfriend, and those issues got cleared up by the time you did it at home. Maybe it was completely random, without any specific identifiable cause.
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Dear Jeff,

Jeff wrote:Looks pretty good. I might use more meaningful loop variables than i and j. Maybe row and column or something like that. And I wouldn't use an explicit, platform-specific "\n" end of line. System.out.print(System.getProperty("line.separator") would be a little better. System.out.println() with no args would be better.
Thanks for wonderful reply.


I realized below things from your another reply
Jeff wrote:Maybe you didn't get enough sleep the night before
100% correct I did not get enough sleep in night. Also I travel for 4 hours from my home to company location which in turn reduce my energy level for thinking.

Jeff wrote:Maybe the stress of the interview setting clouded your thinking.
Yes this is correct and happen due to lack of sleep and long journey. Even not able to write proper SQL query during interview which I am using in current job.

Jeff wrote:when you wrote the code at home, you talked to somebody or saw something online that gave you insight or knowledge that you were lacking during the interview.
Actually I did not speak with anybody or asked about solution when I came back to home.
After some time when my mind got relaxed, I think again on the same program and got solution quickly.

I will take care of above things

Thanks Jeff.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You're welcome. And good luck next time!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Basic Program Asked in Interview