can anyone teach me how to make a java code out of this situation?

here is the situation...

Write a program that accepts 3 integers and display the highest and lowest input. N1=100,N2=200,N3=50.

Thank you!

jwenting commented: no, homework kiddos get no help -3

Could you start by showing us what you've already done?

The heart of this problem is writing a sorting function; however, since there is a small, fixed number of items to compare, it might be easier to do it ad hoc than to write a full function. You could simply do something like this:

set up an integer array of size three
read in the first two numbers
compare the numbers, and put the larger in the array slot 2
put the smaller in the array slot 0
read in the third number
if the third number is smaller than the array[0]
    copy array[0] into array[1]
    copy the third number into array[0]
else if the third number is larger than array[2]
    copy array[2] into array[1]
    copy the third number into array[2]
else
    copy the third number into array[1]

print out the results
Member Avatar for ztini

Could you start by showing us what you've already done?

The heart of this problem is writing a sorting function; however, since there is a small, fixed number of items to compare, it might be easier to do it ad hoc than to write a full function. You could simply do something like this:

set up an integer array of size three
read in the first two numbers
compare the numbers, and put the larger in the array slot 2
put the smaller in the array slot 0
read in the third number
if the third number is smaller than the array[0]
    copy array[0] into array[1]
    copy the third number into array[0]
else if the third number is larger than array[2]
    copy array[2] into array[1]
    copy the third number into array[2]
else
    copy the third number into array[1]

print out the results

That seems like a lot of work and re-engineering. Why not just use the existing API to sort for you?

<CODE SNIPPED>

I was assuming that the sorting was part of the assignment, i.e., something that had to be done manually.

ztini seems to like to show off that he can write code, instead of helping students learn how to write code. Teach a man to fish vs giving him a fish.

commented: Does not contribute to the thread. -1

not to mention overwhelm poor first-time developers. where in the description does it say there is sorting or anything as such needed?

all you need to do is enter three integers, and store the smallest and largest and display these. a simple comparison between two integers is more then sufficient do get this going.

few, why re-invent the wheel and build a car if you can just take the bus around the corner?

commented: Does not contribute to thread. -1

@akasekaihime
1) Sort out your bio description or we will do it for you
2) You are expected to do your part, we are not 24/7 service

@ztini
I snipped code, please do not give out solution so easily. Let poster do their part otherwise you are letting them waste time on facebook, gaming, partying, etc instead of learning. We do not care for lazy people, we care for these who are willing to learn.

Member Avatar for ztini

Hi Peter --

Maybe you can clarify where on http://www.daniweb.com/forums/faq.php?faq=daniweb_policies it says that I cannot post code?

We do not care for lazy people, we care for these who are willing to learn.

That is your opinion and apparently not official policy.

I wonder though--when was the last time you learned code by ... not looking at code? I learn new concepts infinitely faster by seeing examples than I do API. That's me though.

commented: bad, bad, bad manners -3

Its a tough call. The OP's MUST put some effort into it. If they post and then come back and copy and paste, they will learn a lot less than if they spend some time working at the problem. Minimally they should learn how to read the API doc and how to debug.
Most have no idea on debugging their code. The only way you learn how to debug is to have code with bugs that you have to find.
Posted code should be documented enough to explain how and why the code works. Remember these are beginners. We can look at new code for new techniques and learn. A student doesn't have the years of programming experience to build on.
Besides is it fair to their classmates if they get code from here vs generating it themselves.

Member Avatar for ztini

The OP's MUST put some effort into it

Again, opinion and not official policy. The rules clearly state what the OP's "MUST" do.

Most have no idea on debugging their code.

Like using a bunch of System.out's vs a debugger/JUnit? I couldn't agree more .... lol

@ztini rules do not dictate that one is forbidden for giving out code. However we do ask people

Do provide evidence of having done some work yourself if posting questions from schoolwork assignments

That doesn't mean I will go and delete any homework request on forum. I have free hands on decision and it was unfortunate that your code was deleted, but OP

  • damped question on forum
  • gave it all possible highlights
  • failed to provide any evidence of work
  • he returned to check on answer by Schoil-R-LEA, and ignored request to work on it
  • then he returned to check on your answer
  • left without comment

It may be lame from me to delete that code after OP already seen it and presumably copied, but it may send warning to him and others like him reading this, that without putting some effort in it there is no quick solution.

I could go argue more about it but that is pointless. Anyone wishing to discuss this matter is free to send me PM. Thread closed

PS: Question - I wonder though--when was the last time you learned code by ... not looking at code?
Answer - Just last night, I was reading Implementation Patterns.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.