| Author |
solve this please
|
teja dharma
Ranch Hand
Joined: Feb 07, 2009
Posts: 51
|
|
In one of my recent interviews i appeared, they asked a question like this.
when you run" java filename n1 n2 n3 n4" here n1,n2 are integers. n3,n4 are floats.
you must get the output as result of (n1/n2) ,(n3/n4) .
please frame a programme which satisfies the above question.
|
SCJP 5
|
 |
James Tharakan
Ranch Hand
Joined: Aug 29, 2008
Posts: 580
|
|
Just go through the wrapper classes and look in to constructors.
You will find answer
MAke sure you use meaningful title .Not like solve this please
|
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
|
 |
manoj manny
Greenhorn
Joined: Mar 04, 2009
Posts: 4
|
|
public class Test {
<solution deleted>
}
ENJOY
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
Teja Hyd,
When you post a question on JavaRanch, please carefully choose one forum. You have posted this in the SCJP forum, but this questions looks like it does not has anything to do with the SCJP exam.
I will move it to a more appropriate forum for you. Next time, take a moment to think about what forum to post your question in.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
salvin francis
Ranch Hand
Joined: Jan 12, 2009
Posts: 915
|
|
Slightly diff version of the same program:
public class Test {
<solution deleted>
}
Java tiger was not introduced till 1.5 so i would prefer he does not get compiler errors if using an older version.
As an explaination:
java A W X Y Z
'A' is name of class file containing the main program. 'W', 'X', 'Y', 'Z' are the parameters you send to the program. I dont knw the upper limit as to how many parameters can be sent, but they are recieved in a String array which we usually name "args"
|
My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8434
|
|
teja hyd wrote:
Please check your private messages for an importand administrative matter.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8434
|
|
manoj manny wrote:
Please check your private messages for an important administrative matter.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9944
|
|
Please don't post solutions like this. We try very hard here to teach folks how to program, and handing them an answer doesn't accomplish that. Make suggestions, point them towards a class they can use, or even post a code snippet - but not the full blown solutions.
this is particularly important if someone is posting a homework assignment. If they submit what you posted, they can get in trouble for plagarism. I know the O.P. said this was an interview question, but can you really be sure?
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Hector Tenedero
Ranch Hand
Joined: Oct 13, 2008
Posts: 31
|
|
There's a tutorial somewhere in this site that might help you. After reading, it got stuck in my head.
|
 |
teja dharma
Ranch Hand
Joined: Feb 07, 2009
Posts: 51
|
|
James Tharakan wrote:Just go through the wrapper classes and look in to constructors.
You will find answer
MAke sure you use meaningful title .Not like solve this please
dear james in the question n1 n2 n3 n4 i mean they are the parametrs which we give at run time.
execute this programme you can get my question my clear now
public class Sampleinput {
solution deleted. please don't provide direct answers.
}
execute like this
java Sampleinput 4 2 4.0 2.0
you will get the output as
2
2.0
U are preparing for SCJP i think you must be familiar with this topics which worths you
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8434
|
|
"teja hyd",
Did you check your private messages as I had suggested in my previous post?
If not, please do so.
|
 |
Kedar Nath
Ranch Hand
Joined: Sep 02, 2008
Posts: 53
|
|
@ teja hyd
What james said is right. There is a constructor in both Float and Integer class. Which creates an objects of their respective class with string paramaters. And the command lines inputs are taken as strings.
And the solution that you gave is already deleted. And i cant comment on that .
|
 |
James Tharakan
Ranch Hand
Joined: Aug 29, 2008
Posts: 580
|
|
If you are talking about the input other than command line argument, then you can use the scanner class of util package. With it methods like hasnext(), nextInt() and nextFlaot() will give you the solution.
|
 |
 |
|
|
subject: solve this please
|
|
|