How do I access array elements in one method from another method?

Hi all!
How do I access the array's elements from another method so that method 2 can have access to method 1's array elements? Thanks for any help!
I am trying to create a simply program that will use a method to create an array and a SEPARATE method that will sort the array's elements (without using java's built in array features). I can create the program by simply having one method and sorting the array within that same method, BUT I want to sort the array from another method.
Here's my code so far:
public class ArraySort {
   public static void createArray(int size){
       double myArray[] = new double[size];    //create my new array
       for(int j=0; j < myArray.length; j++)
          myArray[j] = (200.0 * Math.random() + 1.0);   //fill the array with random numbers
   public static void sortArray(){
       // I WANT THIS METHOD TO ACCESS THE ARRAY ELEMENTS IN THE METHOD ABOVE, BUT DON'T KNOW
      //  HOW???? Please help!
    public static void main(String[] args) {
        createArray(4);    //call to create the array
}Thanks again!
- Johnny

Thanks for the help all! I ve managed to get the program working, using java's built in array sort, but when i try to call on the array sort method from WITHIN my main method, nothing happens!
Can somebody please tell me why I am not able to call on the sort method from within my main class???? Thanks!
public class ArraySort {
   public void createArray(double[] arrayName, int size){
       double myArray[] = new double[size];  //create new array
       for(int j=0; j < myArray.length; j++)
          myArray[j] = (200.0 * Math.random() + 1.0);    //populate array with
       }                                                 //random Numbers
       sortArray(myArray); 
   } //Sort array(if I delete this & try to use it in Main method --> doesn't work???
   public void sortArray(double[] arrayName){
       DecimalFormat time = new DecimalFormat("0.00");
       Arrays.sort(arrayName);      //sort array using Java's built in array method
       for(int i = 0; i <arrayName.length; i++)
           System.out.println(time.format(arrayName)); //print arary elements
public static void main(String[] args) {
ArraySort newArray = new ArraySort(); //create a new instance
double myArray[] = new double[0]; //create a new double array
newArray.createArray(myArray,4); //build the array of indicated size
//newArray.sortArray(myArray); //This will not work???? WHY?????//

Similar Messages

  • How to refer the trigger written in one form from another form ?

    How to refer the trigger written in one form from another form ?
    Thanks,
    Ravi Shankar

    Try to convert the PL/SQL code from Forms trigger into a PL/SQL library(.PLL),
    and then attach that PLL in your forms.
    Note that all Forms objects should be referenced indirectly, for example,
    you have to rewrite
    :B1.DEPT_CODE := :B2.DEPT_CODE;
    :B3.TOTAL_AMOUNT := 100;
    ==>
    copy('B2.DEPT_NO','B1.DEPT_NO');
    copy('100','B3.TOTAL_AMOUNT');
    This is the best way to share PL/SQL code among Oracle Forms.

  • Hola!  How do I move an element of one picture to another?  PSE10, Windows 7.

    Please let me know how to move an element of one picture to another.  PSE10, Win. 7.

    Jona Lewa Koola wrote:
    Please let me know how to move an element of one picture to another.  PSE10, Win. 7.
    Select the "element" you want to "move" using any of the selection tools available in PSE and then either copy it using CTRL+C or Edit >> copy or cut it using CTRL+X or Edit >> Cut
    Now go to the other image and paste it using CTRL+V or Edit >> Paste
    if you cut it then it will "move" your "element" and remove from the original but if you copy and paste it then both images will have that copied item.
    After pasting it, you may need to move it to the correct location on the target image.
    Hope this helps.

  • How to copy an array element in one class to an array in another class?

    Hi,
    I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
    Is it something like this:
    System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?

    drew22299 wrote:
    Hi,
    I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
    Is it something like this:
    System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?System.arrayCopy will overwrite whatever is already in the array. It is your job to make sure it copies into the proper array location.
    That being said, you're only moving a single student. This is not something you would use arrayCopy for, as you can just do that with simple assignment. Also, you should consider giving Class a method to add a student to its student list, as the class should know how many students it has and can easily "append" to the array.
    Note: I hope you noticed the quotes around append. Java's arrays are fixed size. Once allocated, their size cannot change. You may want to consider using one of the List implementations (ArrayList, for example) instead.

  • How to access the element of one mxml to another mxml?

    Hi,
    I have a component named storylist as below in StoryList.mxml
    <mx:List id="storyList" width="100%" dataProvider="{this.currentDoc.stories}" height="100%" variableRowHeight="true" selectable="false" borderStyle="none"
    itemRenderer="com.xxx.yyy.core.views.renderers.StoryRenderer">
    </mx:List>
    I want to access the storylist in another mxml CoreCanvas.mxml
    private function onOpenFile (doc:IdmlDocument):void {
    logger.info("onOpenFile");
    this.editor.currentDoc = doc;
    this.editor.storyList.dataProvider = this.editor.currentDoc.stories;
    but when  i declared as a bindable variable in StoryList.mxml --> [Bindable] public varstoryList:IdmlStory = null;
    it gives an error
    Description Resource Path Location Type
    1151: A conflict exists with definition storyList in namespace internal. StoryList.mxml/WebEditorCore/src/com/xxx/yyy/core/views/editor line 10 Flex Problem
    how can i access storylist in the other mxml file?
    Message was edited by: Jochem van Dieten

    I'm a bit confused about this design approach.
    [Bindable] public var storyList:IdmlStory = null; 
    The reason why the above line fails to compile in StoryList.mxml is that a variable of the same name already exists. You have specified a List with an id of storyList. The translation process will yield:
    var storyList:List = new List();
    and then fill in the properties.

  • How to add objects to panel in one class from another class

    Hi this is what i am trying to do. I have a drag and adrop tool working where the users and select objects on a small panel and drag them to another panel called the tpan. What i want to do is create another class, which creates objects and now i want to display these objects on the tpan. So say i have a class DisplayTpan(), this class is used to display the objects which have been dragged from the small panel, and objects on this panel have mouselisteners attached, so that these objects can be moved around on the tpan. I have created another class called creatObj(), and from this class i want to add objects to the tpan. The DisplayTpan class extends a Jpanel, would this be he case for the CreateObj() class? In the CreateClass i have made a call to DisplayTpan t = new DisplayTPan();
    t.add(object);
    But this does not add the object to the panel, any ideas on how it should be done?
    Problem number two i have is say, I have two objects created on that oanel, i now want to draw a line t connect the two objects, this is just simply a call to the drawLine function but how would it be possible to add a ,mouselistener to that line, so it can be extended moved around etc? Any help much appreciated thanks.

    Try to convert the PL/SQL code from Forms trigger into a PL/SQL library(.PLL),
    and then attach that PLL in your forms.
    Note that all Forms objects should be referenced indirectly, for example,
    you have to rewrite
    :B1.DEPT_CODE := :B2.DEPT_CODE;
    :B3.TOTAL_AMOUNT := 100;
    ==>
    copy('B2.DEPT_NO','B1.DEPT_NO');
    copy('100','B3.TOTAL_AMOUNT');
    This is the best way to share PL/SQL code among Oracle Forms.

  • How do I mount a disk in one Macbook from another Macbook in order to fix?

    I have a Macbook with Startup disk problems so I want to use DiskWarrior to fix it. I've downloaded DiskWarrior, but the download version doesn't allow me to create a bootable disc to boot from. I'll have to wait for the DVD they are shipping to me for a bootable version. But I need to fix my Macbook asap.
    So I'd like to use my other Macbook to mount the startup disk on the Macbook that's having problems and run DiskWarrior on that disc.
    Can this be done? If so, how?
    Much thanks!

    Hi Jim,
    You can do a Target Disk Mode using a FireWire cable. In the case of double MacBooks, you'd want to use a FireWire 400-to-FireWire 400 (6pin-to-6pin) cable. You can mount the MacBook in question and then tell DiskWarrior to scan that HD.

  • How can i get the stack of one thread from another thread

    hi !
    i have a pool threads ,some times all therads in that pool are besy becouse somting lock the threads so there is no free thread to handle ... .
    what i want is a way to get the stack of these thread so i can print them to see way they lock ...
    thanks,
    zvika

    Maybe something like this (haven't actually tried it):
    Add a method to your Threads to print the trace:
    public class MyThread extends Thread {
        public void run() {
        public void printCurrentStack() {
            (new Exception()).printStackTrace(); // or whatever method you choose
    MyThread mt = new MyThread();
    mt.start();
    mt.printCurrentStack();

  • How to update one table from another

    I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
    I created a table with the following sql of all the affected rows:
    CREATE TABLE LSU_INTER_FIX_DATE AS
    select request_id,received_date,planned_start_date, actual_start_date
    from lsu_inter2_requests_t
    where received_date < to_date('01-JAN-1900')
    OR planned_start_date < to_date('01-JAN-1900')
    OR actual_start_date < to_date('01-JAN-1900')
    I then repaired all of the rows with three data fixes
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
    where planned_start_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
    where actual_start_date < to_date('01-JAN-1900')
    I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
    UPDATE lsu_inter2_requests_t aaa
    SET aaa.received_date = bbb.received_date
    FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
    When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?

    Comet wrote:
    I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
    I created a table with the following sql of all the affected rows:
    CREATE TABLE LSU_INTER_FIX_DATE AS
    select request_id,received_date,planned_start_date, actual_start_date
    from lsu_inter2_requests_t
    where received_date < to_date('01-JAN-1900')
    OR planned_start_date < to_date('01-JAN-1900')
    OR actual_start_date < to_date('01-JAN-1900')
    I then repaired all of the rows with three data fixes
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
    where planned_start_date < to_date('01-JAN-1900')
    UPDATE LSU_INTER_FIX_DATE
    SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
    where actual_start_date < to_date('01-JAN-1900')
    I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
    UPDATE lsu_inter2_requests_t aaa
    SET aaa.received_date = bbb.received_date
    FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
    When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?I am not convinced you have what you think you have
    >
    UPDATE LSU_INTER_FIX_DATE
    SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
    where received_date < to_date('01-JAN-1900')
    When you want to produce a DATE datatype when starting with a string,
    you must use TO_DATE() on the SET line!
    (TO_CHAR(received_date,'RRRR') + 2000)since when do you do add characters (from TO_CHAR) with a constant number (2000)?
    You should NEVER EVER rely on implicit datatype conversion
    Edited by: sb92075 on Jul 27, 2011 7:09 PM

  • How to check string array elements with a string with in one forEach tag ?

    Hi All,
    I am new to JSTL and EL. I need to change the following Java code into JSTL and EL.. I struggled to change this code into JSTL.
    How can i change the if loop which tests the string array element with one bean property ?
    -------------------------------------------------------------------------------------------------------------for(int j=0 ; j < iSelectedCount; j++)
    if(strSelectedRoleId[j].equals(lineRole.getRoleID()))
    isAvailable = true;
    Please help me on this.
    It is very urgent......
    Thank you for ur help,
    Natraj

    import java.util.Calendar;
    Calendar rightNow = Calendar.getInstance();  // gets the current date and time to millisec
    Calendar earlyTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 6).set(Calendar.MINUTE, 30);
    Calendar lateTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 8).set(Calendar.MINUTE, 0);
    if (rightNow.compareTo(earlyTime)> 0 && rightNow.compareTo(lateTime) < 0){
    // do something
    }Try this.

  • How can i access all the objects of one schema from another schema

    Dear All,
    How can i access all the objects(Tables,Views,Triggers,Procedures,Functions,Packages etc..) and do the modifications of one schema from another schema (Without using synonyms concept).
    Thanks in advance,
    Mahi

    First of all, synonyms only help you easy reference the object. It doesn't have any implication of object privilege.
    As long as you have proper privilege on target object. You can access it with or without synonyms.
    Assuming you have proper privilege of objects, you can use following command to assume schema owner.
    ALTER SESSION SET CURRENT_SCHEMA = Schema_owner

  • My new Photoshop Elements 12 has a RAW file plug-in, but when I try OPEN to select a photograph, there are only generic icons instead of pictures-- I can't tell one photograph from another! How can I fix this so I can tell which photograph I want to open?

    My new Photoshop Elements 12 has a RAW file plug-in, but when I try OPEN to select a photograph, there are only generic icons instead of pictures-- I can't tell one photograph from another! How can I fix this so I can tell which photograph I want to open? Thank you!

    Thanks R_Kelly:
    Adobe Photoshop Elements Version: 12.0 (12.1 (20140303.12.1.49334)) x32
    Operating System: Windows Vista 32-bit
    Version: 6.0 Service Pack 2
    System architecture: Intel CPU Family:6, Model:15, Stepping:11 with MMX, SSE Integer, SSE FP, SSE2, SSE3
    Physical processor count: 4
    Processor speed: 2400 MHz
    Built-in memory: 3069 MB
    Free memory: 1631 MB
    Memory available to Photoshop Elements: 1598 MB
    Memory used by Photoshop Elements: 69 %
    Image tile size: 128K
    Image cache levels: 8
    Video Card: ATI Radeon HD 4800 Series
    Video Mode: 1680 x 1050 x 4294967296 colors
    Video Card Caption: ATI Radeon HD 4800 Series
    Video Card Memory: 512 MB
    Application folder: C:\Program Files\Adobe\Photoshop Elements 12\
    Photoshop Elements scratch has async I/O enabled
    Required Plug-ins folder: C:\Program Files\Adobe\Photoshop Elements 12\Required\
    Primary Plug-ins folder: C:\Program Files\Adobe\Photoshop Elements 12\Plug-Ins\
    The first thing I did was UPDATE. I have all the latest updates available (according to the updater). The Camera Raw Plug-in says it is version 8.0.
    The RAW files are from a Canon T3i. It's a very common camera, I can't believe it wouldn't be supported.

  • How to set an array element in an object type of array??

    Hi,
    I have set attribute as follow:
    Color[] colors;
    Color[] colors = new Color[20];
    colors[0] = "Red";
    colors[1] = "blue";I can't compile this code. It said:
    "Incompatible type -found java.lang.String but expected Colors
    Could you tell me how to set an array elements when the array type is an object?

    in your case, the array shouldn't be Color[] but String[] since you re intending to put strings into it
    by the way, you could also use a hashmap to map a string to a color:
    HashMap<String, Color> hm = new HashMap<String, Color>();
    hm.put("Red", Color.RED);
    hm.put("Blue", Color.BLUE);
    etc.

  • How do I access and use my Itunes library from a different/new computer?

    How do I access and use my Itunes library from a different/new computer?  My computer is no longer working, so I need to be able to access my library from my wife's computer.

    Your library will only be where you put it.  Copy everything from your backup copy of your old computer to the new one.
    You can redownload some itunes purchases in some countries:
    Download past purchases - Apple Support

  • How can I to control any element of my GUI from another class?

    How can I to control any element of my GUI from another class?

    For that, you need the external class to have the reference to your element.. If your idea is to change basic properties like width, height etc.. then you can have the constructor of the external class to take the object of the parent of your class as the parameter and modify ..
    However, if the properties to be altered/accessed are custom to your element, then you will have to have the class accept an object of your class as the parameter. No other option..
    What exactly is your requirement?

Maybe you are looking for

  • Dundas Chart for Reporting Services in SSRS 2012

    We are in the process of upgrading our servers to 2012 and though I find many things about converting or upgrading dundas controls to 2008, I can't find anything about upgrading/converting to SSRS 2012.  After converting the development machines to S

  • Word 2004 for Mac "Notebook"

    Hi, I'm a new Mac user. I've been using Microsoft Word 2004 for Mac's "Notebook" feature to take notes and record the audio for my class lectures. In the last week, my MacBook has locked-up three times when trying to stop the audio recording at the e

  • How do i shuffle music under a specifi genre in the new ios 7?

    how do i shuffle music as a genre in the new ios 7?  it only lets me pick a specific artist, and shuffle his/her songs, as opposed to shuffling the whole genre itself.

  • Trusted certificates from your previous version of Adobe Reader were found.

    After upgrading Adobe Reader from 10 to 11, some users are getting "Adobe Reader Security - Trusted certificates from your previous version of Adobe Reader were found.  Would you like to import them."  I need to know what registry settings we can mod

  • LSMW and "Zone GL_EMPL-USERNAME" error

    Hi all, I built an LSMW project (type Idoc) to create Business Partners (under CRM 5.0).  When I try to create a "person", I can't find any field in Structure relation (and Field Mapping) to fill the BP's "Username" field (under the "Identification"