File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

solve this please

 
teja dharma
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
manoj manny
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Test {
<solution deleted>
}

ENJOY
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
salvin francis
Bartender
Pie
Posts: 1213
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
teja hyd wrote:


Please check your private messages for an importand administrative matter.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manoj manny wrote:


Please check your private messages for an important administrative matter.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Hector Tenedero
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a tutorial somewhere in this site that might help you. After reading, it got stuck in my head.
 
teja dharma
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic