Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Simple Logic Question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! I'm very new to Java, so please be gentle *_*
I'm trying to write a .java file that will get three numeric values from the user, sort them in ascending order, and print the sorted values.
This is the basis for the program:The most important thing is to be able to make this work with ONLY 3 IF statements.
Can anyone help? I assume it's pretty easy...but I have not been able to figure it out.
Thank you so much in advance...
/JM
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 02, 2003: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why not use an array of integers instead. try this (selection sort):-

im not sure if it is correct. basically how it work :-
1) find the smallest element of the array(from index j+1 to the end of the array)
2) swap it with index at k
hope this helps.
[ March 02, 2003: Message edited by: Syamsul Hussin ]
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put 3 coins of different size on the tabletop.
What comparisons do you need to make to see which is the biggest, smallest and the mid-sized coin?
Once you have a system that works, see if you can reduce it to 3 comparisons.
Sometimes it helps to (1) assume that whatever your looking for is the first one you get then (2) compare at all others and if you assumtion proves wrong, change your choice.
[ March 02, 2003: Message edited by: Elouise Kivineva ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also do it with no ifs if you use the Arrays class and the appropriate sort() method.
 
J Morberg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everyone for your help~!
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You could also do it with no ifs if you use the Arrays class and the appropriate sort() method.


Yes, and actually, anything else would be a suboptimal solution. Why code the buble-heap-selection-quicksort routines from scratch if you have a standard, well tested, language-supported functionality?
Incidentally, the default sort implementation in JDK1.4.1 is the modified mergesort which guarantees Nlog(N) performance.
Eugene.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic