Sorting Numbers stored in variables....using if/else

Hey there, I'm curious, how would you sort 3 integers using only five if's and five elses and no other operators besides a < (less than) operator? Some help would be much appreciated! thanks. ishan

well with the topic i brought back there, didnt
really follow the boolean, and i couldnt figure out a
way to simply use only if's elses' and > rather than
using boolean, and what not.. like for integer a, b,
c; would i go into the possible permutations and
start from there? not sure how to go about it..You will need to put them in an array or List. Then you can quicksort them.
Hmmm let me think....
if
  length<2 return
choose pivot
if less than pivot
  put in left bucket
else
  put in right bucket
recurse left bucket
recurse right bucket
returnThat's 2 if's and one else.

Similar Messages

  • Sorting numbers stored in variables

    I'm completely new at java and would like some help with a certain problem.
    I have 5 numbers, num1, num2, num3, num4, and num5.
    I have them stored in variables as listed. I'd like to know, is there a way to sort them using array.sort or would I have to use another method?

    I have 5 numbers, num1, num2, num3, num4, and num5.
    I have them stored in variables as listed. Are you saying you have 5 different ints declared like
    int num1, num2, etc.or an int[] with length 5?
    I'd like
    to know, is there a way to sort them using array.sort
    or would I have to use another method?If they are stored in an array you can use http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#sort(int[])
    to sort them.

  • Creating java program that orders 3 numbers in ascending order using if els

    Does anyone know what code to use for creating a java program that uses the if else operators to order 3 variables in ascending order?

    nar0122 wrote:
    correct on the homework assumption...you have a good nose...the thing is...i know i need to make an if statement saying if a is less than b, and a is less than c...print a first...but how do i get it to "print a" first? if a is less than c and b...and so on for b and c? sorry if that was confusing...
    int a = ..., b = ..., c = ...;
    if(a > b AND a > c) {
      print a
      if(b > c) {
        print b, print c
      } else {
        print c, print b
    etc.

  • Sorting numbers stored as text

    Business1 stores ItemCode as an alphanumeric, which makes sense.  But we only ever use numbers, so when I try to sort a report by ItemCode, or select a range by ItemCode I get things like this:
    4100
    41001
    4101
    4102
    42001
    42003
    42004
    4201
    Can I get CR to treat these as numbers, and sort/select them as numbers?

    Hi Stuart,
        try to use any one formula given below , and try to short on this formula field
           1] right("00000000" & ,10)
                               or
           2] toNumber()
    You can suppress this field,so it will not be visible to the user
    Regard's

  • As of Contract Management 13, serial numbers are no longer used.

    Hello Primavera users,
    We are currently using Contract Manager v12 on a major program here in the UAE and looking to upgrade soon to v13.
    Regarding this knowledge base posting (below), does v13 still support concurrent user licenses, and if so what are Oracle's plans moving forward in terms of Contract Manager?
    I would love to hear the views of the Primavera community, especially in relation to these changes with serial numbers etc...
    Thanks & Regards,
    John
    Solution ID: prim83632
    How To: Adding (new) serial numbers in Contract Management 13
    Status: Reviewed
    Version(s): 13.0
    Problem:     How To: Adding (new) serial numbers in Contract Management 13
    Problem:     Where do I add new serial numbers in Contract Management 13?
    Problem:     Where are serial numbers stored?
    Fix:     As of Contract Management 13, serial numbers are no longer used.

    Well, it's just a simple pipe afterall, a tool to give you brief information upon which you decide what to do. Also, there's a minor annoyance, it should go like this:
    stat -c '%x %n' /usr/bin/* | sort
    I mixed long and short options for a moment there, that gets rid of the '=' in front of every line.

  • Unable to access value in System Environment Variable using Java

    I am using Java code to get the value of a System Environment Variable using the Runtime, Process java classes.
    The code works fine in tomcat, but when deployed in 9ias the code is unable to retrieve the value stored in the System environment variable in Windows 2000.

    Thanks for the comment steve, here is the code which i am using.
         public String getEnvironmentVariable()
                   // This will get the FEDREP_HOME environment variable
                   String FEDREP_HOME = null;
                   Process p = null;
                   Runtime rt = Runtime.getRuntime();
                        try {
                             // invokes a shell-command to retrieve FEDREP_HOME variable
                             String OS = System.getProperty("os.name").toLowerCase();
                                  // Get the Windows 95 environment variable
                                  if (OS.indexOf("windows 9") > -1)
                                            p = rt.exec( "command.com /c echo %FEDREP_HOME%" );
                                  // Get the Windows NT environment variable
                                  else if (OS.indexOf("nt") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the Windows 2000 environment variable
                                  else if (OS.indexOf("2000") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the Windows XP environment variable
                                  else if (OS.indexOf("xp") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("linux") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("unix") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("sunos") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  } else
                                            System.out.println("OS not known: " + OS);
                             // set up to read subprogram output
                             InputStream is = p.getInputStream();
                             InputStreamReader isr = new InputStreamReader(is);
                             BufferedReader br = new BufferedReader(isr);
                             // read output from subprogram
                             FEDREP_HOME = br.readLine();
                             br.close();
                        } catch(Exception ex)
                                  System.out.println("Error when getting FEDREP_HOME environment variable");
                                  ex.printStackTrace();
              return(FEDREP_HOME);

  • How to get values from a stored package variable of type record ?

    Sir,
    In my JClient form, I need to get values from a database stored package variable of type record. And the values are retained in the JClient form for the whole session. The values are copied only once when the form is started.
    What is the best way to do that ?
    Thanks
    Stephen

    Stephen,
    not sure what your model is, but if it is Business Components, I think I would expose the properties as a client method on the application module. This way all JClient panels and frames will have access to it. You could use a HashMap to store the data in teh app module.
    If JDBC supports the record type, then you should be able to call it via a prepared SQL statement. If not, you may consider writing a PLSQL accessor to your stored procedure that returns something that can be handled.
    Steve Muench provides the following examples on his blog page
    http://otn.oracle.com/products/jdev/tips/muench/stprocnondbblock/PassUserEnteredValuesToStoredProc.zip
    http://otn.oracle.com/products/jdev/tips/muench/multilevelstproc/MultilevelStoredProcExample.zip
    Frank

  • Problems in creating and storing new documents using BAPI_DOCUMENT_CREATE2

    Hi experts,
    I'm getting problems in creating and storing new documents using BAPI_DOCUMENT_CREATE2.
    I have a scenario where is defined the document type ZC1, document part 200, authorization group 0002 and for all of these  documents the storage category "Cofre DMS1". And the status which demands the storage category is 'FR'.
    I've been fullfiling the BAPI_DOCUMENT_CREATE2 in this way:
    "Tables
    data: it_doc like bapi_doc_draw2,
          it_return like bapiret2,
          it_files like bapi_doc_files2 occurs 0 with header line,
          it_objs like bapi_doc_drad occurs 0 with header line.
    "Variables
    data: wl_doctype like bapi_doc_draw2-documenttype,
          wl_docnumber like bapi_doc_draw2-documentnumber,
          wl_docpart like bapi_doc_draw2-documentpart,
          wl_docversion like bapi_doc_draw2-documentversion.
    it_doc-documenttype = 'ZC1'.
    it_doc-documentpart = '200'.
    it_doc-documentversion = '00'.
    it_doc-description = 'Test of documents creation via BAPI'.
    it_doc-username = sy-uname.
    it_doc-statusextern = 'FR'.
    it_doc-authoritygroup = '0002'.
    refresh it_files[].
    clear it_files.
    it_files-originaltype = '1'.
    it_files-storagecategory = 'Cofre DMS1'.
    it_files-wsapplication = 'PDF'.
    it_files-docfile = 'c:\110307.pdf'.
    it_files-description = 'Test file'.
    append it_files.
    refresh it_objs[].
    clear it_objs.
    it_objs-objecttype = 'EKPO'.
    it_objs-objectkey = '47000497600010'.
    append it_objs.
    CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
      EXPORTING
        documentdata = it_doc
      IMPORTING
        documenttype = wl_doctype
        documentnumber = wl_docnumber
        documentpart = wl_docpart
        documentversion = wl_docversion
        return = it_return
      TABLES
        objectlinks = it_objs
        documentfiles = it_files.
    After execute the BAPI process I got the following error:
    E26 087 - Data carrier COFRE DMS1 not defined
    Does anybody have a sugestion to help me, please?
    Thks
    David
    Edited by: David Tsutsui on Mar 18, 2010 10:52 AM

    Please refer to this thread, it tells why you need a data carrier you can also configure the same in DC20.
    Data Carriers for Storage the Originals of DMS

  • Behavior of customer exit variables (used as prompt) in a workbook

    Hi All,
    We are on NW2004s. I am using a customer exit variable in the prompt for my query then saved the query as a workbook.
    1. When I run the query the customer exit routine/program is called and the selection screen variable is populated with the correct value.
    Ex. Calendar year variable is a prompt variable defined as customer exit variable that gets the current year.
    when you run the query the prompt for calendar year shows "2007" as default value. this is correct.
    2. when I run the workbook using this same query, it looks like it is not executing the customer exit program. The value in the calendar year prompt is whatever the last value used when the workbook was last ran.
    I also placed a breakpoint in the customer exit program (EXIT_SAPLRRS0_001) to check if it is being called and it looks like it isn't.
    Is there a configuration/property that I should enable/check to make sure that customer exit variables used as prompts works in workbooks? Is this a bug? Anybody else have issues with using customer exit variables as prompts in their workbooks?
    Thanks in advance,
    Malou

    Hello Marilou,
    See the abswer I got from the 1st response on my question
    Save and reuse variable option in 7.0
    It may be a good help.
    Variables seem to be an understated item in the documents.
    Kind regards
    Message was edited by:
            BI developer

  • Sorting a vector of objects using attribute of object class as comparator

    i would like to sort a vector of objects using an attribute of object class as comparator. let me explain, i'm not sure to be clear.
    class MyObject{
    String name;
    int value1;
    int value2;
    int value3;
    i've got a Vector made of MyObject objects, and i would sort it, for instance, into ascending numerical order of the value1 attribute. Could someone help me please?
    KINSKI.

    Vector does not implement a sorted collection, so you can't use a Comparator. Why don't you use a TreeSet? Then you couldclass MyObject
      String name;
      int value1;
      int value2;
      int value3;
      // Override equals() in this class to match what our comparator does
      boolean equals (Object cand)
        // Verify comparability; this will also allow subclasses.
        if (cand !instanceof MyObject)
          throw new ClassCastException();
        return value1 = cand.value1;
      // Provide the comparator for this class. Make it static; instance not required
      static Comparator getComparator ()
        // Return this class's comparator
        return new MyClassComparator();
      // Define a comparator for this class
      private static class MyClassComparator implements Comparator
        compare (Object cand1, Object cand2)
          // Verify comparability; this will also allow subclasses.
          if ((cand1 !instanceof MyObject) || (cand2 !instanceof MyObject))
            throw new ClassCastException();
          // Compare. Less-than return -1
          if ((MyObject) cand1.value1 < (MyObject) cand2.value1))
            return -1;
          // Greater-than return 1
          else if ((MyObject) cand1.value1 > (MyObject) cand2.value1))
            return 1;
          // Equal-to return 0.
          else
            return 0;
    }then just pass MyObject.getComparator() (you don't need to create an instance) when you create the TreeSet.

  • Session variable using :GROUP variable in init block

    I'd like to filter using session variable.
    This session variaible should be build using :GROUP special session variable
    I'd like do something like this (init block):
    select  case when instr(upper(':GROUP'), 'ADMINISTRATOR')>0 then 'Yes' else 'No' end from dual
    but it seems to doesn't work properly (It means I have always 'No' value)
    After investigation i did some simple test
    initialization block like this:
    select  upper(':USER'),upper(':GROUP') from dual
    set variables using above init block: UPP_USER and UPP_GROUP
    next i did simple reques with 4 columns:
    *1. VALUEOF(NQ_SESSION.USER)*
    *2. VALUEOF(NQ_SESSION.GROUP)*
    *3. VALUEOF(NQ_SESSION.UPP_USER)*
    *4. VALUEOF(NQ_SESSION.UPP_GROUP)*
    and my result is:
    1. Administrator
    2. Administrators;IT_Deparment ....
    3. ADMINISTRATOR
    4. _:GROUP_
    Why in 4th column I didn't get: ADMINISTRATOR;IT_DEPARTMENTS ....
    Can I use special variable GROUP in initialization block?
    Could someone explain it?

    Hi,
    Only :USER and :PASSWORD are available
    try (select 'VALUEOF(NQ_SESSION.USER)', 'VALUEOF(NQ_SESSION.GROUP)' from dual instead.
    (You migth have to force a fill of the group variable first)
    Regards
    John
    http://obiee101.blogspot.com/

  • Error : A READ-ONLY bind variable used in OUT or IN-OUT context

    Hi,
    I got error from my report as A READ-ONLY bind variable used in OUT or IN-OUT context in formula column. I already face this problem but at that time i cleared , but now i cont able to do, please give suggestion to this
    regards
    venki

    I find my ERROR in that report, that A READ-ONLY bind variable used in OUT or IN-OUT context is
    when we assign a database column in a placeholder are summary column.
    From that placeholder or summary column will call by formula column
    you might be face that error, But how means
    when that database column , we are assign that decode, case or NVL funtion using else condition as Null you may be face that error.
    Without my knowledge it may seem some other problem also
    without any idea we con't able to clear this error.
    venki

  • Sorting numbers Zen Mozaic EZ 100

    !Sorting numbers Zen Mozaic EZ 00= Hi, I have a Creative Zen Mozaic EZ 00, and I use this player primary for <span class="Apple"><span class="Apple">Audiobook.
    <span class="Apple"><span class="Apple">I have a problem when I transfer more than book to my player.
    <span class="Apple"><span class="Apple">?
    <span class="Apple"><span class="Apple">When I use the Albums, alle the files are not sorted, why isn't is sorted using the filename.
    <span class="Apple"><span class="Apple">?
    <span class="Apple"><span class="Apple">The only solution I have found, is using all tracks, here the files are sorted in filename order.
    <span class="Apple"><span class="Apple">?
    <span class="Apple"><span class="Apple">How do I sort the files in folders or Albums.
    <span class="Apple"><span class="Apple">?
    <span class="Apple"><span class="Apple">Kind regards,
    <span class="Apple"><span class="Apple">Kenneth

    Hi,
    Did you transfer the audiobook using Audible Manager?

  • Invoking Stored procedures without using CallableStatement

    I have a piece of code:
    import java.sql.*;
    public class Somenath{
    public static void main(String args[])throws ClassNotFoundException,SQLException{
    String abc;
    String query="{ call PR_EXAMPLE_I(?,?) }";
    String name="TEST FUND 2";
    Connection con = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@172.16.31.120:1521:ora9db","gs2","gs2");
    Statement statement=con.createStatement();
    CallableStatement cs = con.prepareCall(query);
    cs.registerOutParameter(2,Types.VARCHAR);
    cs.setString(1,name);
    cs.execute();
    String nameval=cs.getString(2);
    System.out.println("Name"+nameval);
    try{
    finally{
    cs.close();
    This code works fine.
    I would like to know wheather its possible to execute a stored procedure using the
    statement.execute()/statement.executeQuery().Please note as per Java's documentation statement.execute() may be used execute any unknown SQL String.So is it possible to execute a stored procedure thats already existing(say PR_EXAMPLE_I in the current example).

    Thank you Digital Dreamer for ur help.I will explain the problem in detail.
    Well I wish to invoke a stored procedure that uses a in paramater but no out parameter.Assume that the stored procedure (say abc) already exists in the system.We execute a Select statement inside the Stored procedure and copy the value in a block-variable(a local one) within the Stored Procedure.
    Usually we execute the stored procedure in the SQL Prompt using
    SQL> exec Proc_Name(In Paramter)
    I would like to know how do I do it in JDBC using Statement.(Please note that we are not using Callable Statement)
    Can u help me out with an example?

  • I need help regarding measurement of "time domain parameters of Heart rate variability" using labview.

    I need help regarding measurement of "time domain parameters of Heart rate variability" using labview.
    I am using Labview 8 ... I  need to develop a software to accquire the ECG data (simulated enironment ) and compute the time domain parameters of Heart rate variability like "SDNN, SDANN...etc". Can some 1 plllzzzz help me out.Plzz help me if u can.Thanx in advance.

    Hi Andy,
      Thanx for responding.  The input is from a text file. SDNN, SDANN,etc are  the timedomain parameters of heart rate variability.
     SDNN: the standard deviation of the NN or RR interval  i.e. the square root of variance.
    SDANN:the standard deviation of the averageNN interval calculated over short periods, usually 5 min,which is an estimate of the changes in heart rate due tocycles longer than 5 min
    SDNN index, the meanof the 5-min standard deviation of the NN intervalcalculated over 24 h,
     RMSSD: the square root ofthe mean squared differences of successive NN intervals
    NN50: the number of interval differences of successiveNN intervals greater than 50 ms, and
    pNN50 the proportionderived by dividing NN50 by the total numberof NN intervals.
    The problem is dat I am a fresher to the world of Labview. I have jus recently started working on it. Can u please suggest me some some idea as soon as possible.
      As i said  I have the ECG data in the form of text files..I need to create sort of GUI to calculate the time domain parmeters....I need help urgently. Plzzz help me if u can. If u have and .vi example to calculate the RR interval plzz send it to me ASAP.
    Thanku

Maybe you are looking for

  • Flip or spin in Graphic

    Does anyone have any idea how to spin in a graphic? When I apply the 'flip' effect, it also affects the video below. I can't even spin it using keyframes because FCP X doesn't work in 3D space. This will explain it a little better. http://www.youtube

  • User created SQL Agent Job that uses linked server with Windows authentication

    OK, here's what I want to do, but not sure exactly what I need to accomplish it. Environment Windows 2008 Enterprise SQL 2012 Enterprise SQL Server & SQL Agent running under AD account (which has local Windows Administrative privileges...yes, I know.

  • TV SideView support for Xperia ZL IR blaster

    Phone: Xperia ZL C6506, Android 4.2.2 build 10.3.1.A.2.67 TV SideView version 2.2.2 I have my cable STB box added via the built-in Remote Control app and the box can be successfully control from the phone. However, it seems that the TV SideView app t

  • How to name or rename iTunes tracks.

    Hi. I have put a cd into iTunes. The names of the  tracks are  are shown as Track1, Track 2, etc. This seems to be normal,  as the cd was given to me by my son who burned it with  songs he liked. I now want to put names on each track. I can't find in

  • Sending LINKS to sites does not work on friend's computers

    What is the problem? There are two choices to send a site to someone....Mail contents of this page, or Mail link to this page... I keep getting replies saying there's no attachment or no link to click.... what is the problem???????????????????