This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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"
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?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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 .
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.