Array in Order

im trying to make a method that takes in an array and makes a new array with the values from 0 to the array.length-1 so that the array it returns will corrispond with the values in the original array (if the number at the original element[ n ] is the higest number of all the array its value in the new array would be array.length-1
examples:
{81,-81,10,2,-2,-10} becomes {5,0,4,3,2,1}
{79,-17,2,0,0,-2} becomes {5,0,4,2,3,1}
{80,-80,0,0,0,0} becomes {5,0,1,2,3,4}
i tried something like this:
int[] newOrder = new int[order.length];
for(int i = 0; i < newOrder.length; i++)
newOrder=0;
for(int h = 0; h < order.length;h++)
for(int g = 0; g < order.length;g++)
if(order[h]>order[g])
newOrder[h]++;
cept with that if i send it {80,-80,0,0,0,0} it comes out {5,0,1,1,1,1} which is not what i want, i want each number to be a differnt number between 0 and array.length-1

Try something like this:public int[] order(final int[] array) {
  int[] temp = new int[array.length];
  for(int i = 0; i < array.length; i++)
    temp[i] = array;
java.util.Arrays.sort(temp);
java.util.List list = new java.util.ArrayList();
for(int i = 0; i < array.length; i++)
list.add(new Integer(temp[i]));
temp = new int[list.size()];
for(int i = 0; i < array.length; i++) {
Integer n = new Integer(array[i]);
int index = list.indexOf(n);
temp[i] = index;
list.set(index, null);
return temp;
I didn't comment or test it, so you'll need to see for your self how (and if) it works.
Good luck.

Similar Messages

  • How to reverse array display order?

    Is there a way to reverse the way labview displays array data?  When using a boolean array I would like the LSB to be on the right side.
    I know that you can use the reverse array function, but that changes the actual data. I would rather just change how the data is displayed.  Also I have quite a few and don't want to have to add that to all of them.
    Thanks

    It should be fairly trivial to add a reverse array before displaying the data. Keep in mind, when you display the data on the Front Panel, you can keep a parallel branch wire on the Block Diagram that is not affected by the Reverse Array.
    Also, if you are displaying many of these arrays, perhaps you could use a 2D array on the Front Panel to show all bitmaps at once? Or, a 1D array that contains a cluster of the Boolean array if the Boolean arrays are ragged/jagged. Using this method would be scalable, meaning you would need only 1 Reverse Array for N arrays you want to display.
    And smercurio_fc is right about the XControl being able to display a reversed array. But if you're not willing to drop Reverse Array in a few places, you're probably not willing to bite off the non-trivial task of creating an XControl (there's a moderate learning curve for getting the hang of creating a good XControl).
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

  • What is the best way to create diagonal array in order to avoid MEMORY IS FULL error created by using INITIALIZE ARRAY vi?

    Using the values in a 1D array, I need to place them along the diagonal of a 2D array. Currently, I've been using INITIALIZE ARRAY VI to create 2D array of zeroes and then usE REPLACE ARRAY SUBSET to put the 1D array values on the diagonal. This works sometimes but I often get an error stating that the memory is full and that the application was stopped at INITIALIZE ARRAY.
    I'd appreciate any advice on how to stop this from occuring.
    Thanks and happy holidays,
    Hunter (LabView 6.1 user)

    Weather is the same here, too.
    Sorry about the PDF. I had forgotten about the PRTSCN option. See the attached JPG.
    I'd send you an example input that is giving me problems but today, my computer seems to be behaving and the error hasn't popped up. This makes me believe that it's truly a memory problem with my machine.
    This VI is a subVI used in several computationally intensive applications.
    If you're still interested in playing with it, I will email it to you. Please send me your address. In fact, I see you're in the oil & gas industry and I'd like to hear what you're working on since I work in that industry as well.
    Thanks again, Hunter ([email protected])
    Attachments:
    VI_Diagram.jpg ‏104 KB

  • Error in file export when order of elements in build array changes

    Hi everyone,
    A while ago I wrote a vi file which does the following:
    At first it initializes a camera and chooses a region of interest (ROI). Data out of the ROI will be discarded.
    Then it raster scans a motor stage in x and y direction, in bidirectional mode (meaning that x alternates between scanning from left to right and right to left as y is inreased).
    For each point of the scan, the spectrum is collected, which is then integrated in lambda to give an idea of the total intensity.
    Then the intensity is plotted, along with the spectrum at each point.
    The final results are exported in a text file.
    The problem:
    If I flip the order of the wires in the "build array" before the file export, placing the Total Count (intensity) wire in place of the Spectrum wire, the file export fails. What I mean by "fails" is that the .txt file contains characters that look like chinese!
    Why is that?
    I attach my .vi as well as two screenshots which demostrate the problem.
    Solved!
    Go to Solution.
    Attachments:
    correct.png ‏182 KB
    Wrong.png ‏180 KB
    1.7z ‏119 KB

    mikeporter wrote:
    Hey Jeff... The changes you recommend are all good (and necessary) but the thing I'm stuck on is that regardless of what happens to the floating point data, there's that built-in VI that changes it to string representations of the numbers. And as I understand it, that is where the problem is.
    Mike...
    PS: Coming to NI Week?
    Not this year
    What scared me was the sgls on a SLs with no wire branch to force a data copy which, would force LabVIEW to preserve the sgls since the SL might need to be used again then, they get all mixed up building arrary out of mixed coerced sgls and dbls.  With the potential of a miss-reussed buffer (not uncommon in 2011) confusing the string operations in the write to spreadsheet.   The problem of course, must exist outside of write to spreadsheet file since it only exhibits with a build array element order change.  Or, we all are halucinating (Possible alternate theory)  
    Jeff

  • Ordering an array

    i have an array with 13 strings;
    i'd like a clue to how could i rearrange the array's order acordinglly to a particular substring inside each string.
    in other words, i can generate 4 hands of 13 cards each; each element has 2 parts: the name and the suit.
    I want to order by suit.

    You can't do anything in Java without writingmethods.
    i know that
    just asking for a clueOkay...
    Define a class called Card or PlayingCard. This class will mainly just be a data container--a way to group the suit and rank attributes (shutup jschell).
    You now have two choices. This Card class can implement Comparable or you can define a Comparator
    In the first case, your class has a "natural ordering" built into it. This means that each card knows whether it's less than, equal to, or greater than some other card.
    In the second case, the cards by themselves don't know their ordering relative to other cards. Rather, there's an external class (the Comparator) that compares two cards for less, equal, greater.
    In both cases, there's one method you'll have to write. It compaes two cards according to your rules and returns a negative number, zero, or a positive number, depending on the relative "values" of the two objects. In both cases, you should also override equals and hashCode.
    Also in both cases, you don't have to write the sorting algorithm. There are methods for both cases to do the sorting. You give them either and array or List of items that implements Comparable, or an array or List of items and a separate Comparator. These methods then do the sorting, using your rules as to what it means to be less, equal, or greater.
    You said you want to sort by suit. Presumably you'll sort by both attributes, but are you saying you want suit to take higher precedence?
    5S, 7S, 3C, 6C
    vs.
    3C, 5S, 6C, 7S
    What you'd do in your comparison method then is compare suit first. If they're unequal, you're done. If suit is equal, then you compare rank and return the result of that.
    Just like when you're alphabetizing. You compare letters until you hit a pair that are unequal and then use the results of that comparison
    cafe
    card

  • Assigning Values from a file to an Array

    hey everyone I am working on a program that inputs values from a text file into an array i got the first array to work but the second array does not work. Please if you have a moment lend a hand. Here is my code. the program compiles fine but will not run right with the second array in it. The second array is called "B"
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    class algorithmAssignment1{
         public static void main (String[] args)throws IOException{
         int mark, counter, arrayAsize, mark2;
         counter=0;
         arrayAsize=100;
         int [] A= new int[arrayAsize];
         int [] B= new int[arrayAsize];
        String fileName = "arraynumbersa.txt";
        String value,value2;
        BufferedReader input;
        input = new BufferedReader (new FileReader (fileName));
        value = input.readLine ();
       while (value != null){
           mark = Integer.parseInt (value);
           A[counter]=mark;
           counter=counter+1;
           value = input.readLine ();
      /*  String fileName2 = "arraynumbersb.txt";
        BufferedReader input2;
        input2 = new BufferedReader (new FileReader (fileName2));
        value2 = input2.readLine ();     
         while (value2 != null){
           mark2 = Integer.parseInt (value2);
           B[counter]=mark2;
           counter=counter+1;
           value2 = input2.readLine ();
         bubbleSort(A,A.length);
         bubbleSort(B,B.length);
         System.out.println("Here is list A");
         for (int i = 0; i < A.length; i++){
             System.out.println( A[i] );
        System.out.println();
        System.out.println("Here is list B");
        for (int i=0;i<B.length;i++){
             System.out.println(B);
    /*change
    for (int i=0;i<A.length;i++){
         for (int j=0;j<B.length;j++){
              if (A[i]==B[j]){
                   System.out.println("Numbers that are in list A and B are "+ B[j]);
    static void bubbleSort(int numbers[], int array_size){
         int i, j, temp;
         for (i = (array_size - 1); i >= 0; i--)
         for (j = 1; j <= i; j++)
         if (numbers[j-1] > numbers[j]){
         temp = numbers[j-1];
                             numbers[j-1] = numbers[j];
                             numbers[j] = temp;

    Ok new problem now. I have to get the duplicates to go into a new array in order to display the duplicates. I can't figure out why it just lists the one duplicate but not the others.(It lists the final duplicate)
    Here is my code:
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    class algorithmAssignment1{
         public static void main (String[] args)throws IOException{
         int mark, counter, arrayAsize, mark2,counter2;
         counter=0;
         arrayAsize=100;
         counter2=0;
         int [] A= new int[arrayAsize];
         int [] B= new int[arrayAsize];
         int [] C=new int [arrayAsize];
        String fileName = "arraynumbersa.txt";
        String value,value2;
        BufferedReader input;
        input = new BufferedReader (new FileReader (fileName));
        value = input.readLine ();
       while (value != null){
           mark = Integer.parseInt (value);
           A[counter]=mark;
           counter=counter+1;
           value = input.readLine ();
        String fileName2 = "arraynumbersb.txt";
        BufferedReader input2;
        input2 = new BufferedReader (new FileReader (fileName2));
        value2 = input2.readLine ();     
         while (value2 != null){
           mark2 = Integer.parseInt (value2);
           B[counter2]=mark2;
           counter2=counter2+1;
           value2 = input2.readLine ();
         bubbleSort(A,A.length);
         bubbleSort(B,B.length);
         System.out.println("Here is list A");
         for (int i = 0; i < A.length; i++){
             System.out.println( A[i] );
        System.out.println();
        System.out.println("Here is list B");
        for (int i=0;i<B.length;i++){
             System.out.println(B);
    for (int i=0;i<A.length;i++){
         for (int j=0;j<B.length;j++){
              if (A[i]==B[j]){
                   for (int k=0;k<C.length;k++){
                        C[k]=(B[j]);
                   System.out.println("Here"+B[j]);
    System.out.println("Here are A and B");
    for (int i=0;i<C.length;i++){
         System.out.println(C[i]);
    static void bubbleSort(int numbers[], int array_size){
         int i, j, temp;
         for (i = (array_size - 1); i >= 0; i--)
         for (j = 1; j <= i; j++)
         if (numbers[j-1] > numbers[j]){
         temp = numbers[j-1];
                             numbers[j-1] = numbers[j];
                             numbers[j] = temp;

  • Save 2D array in write to spreadsheet file

    Hello,
    I want to save 2 signals coming from 2 channels in  1 file ( as a 2D file:
    column 1 for signal coming from channel 1, and column 2 for signal coming from channel 2).
    How I can do it?
    See my example please. I can save these 2 signals on 2 different files.  I
    can not find a way to put them in on file.
    Thank you so much.
    Pascal
    Attachments:
    2 signal save.vi ‏80 KB

    Since the output of AI Read is a 1D array of waveforms you have to extract the data of each waveform and create a 2D array in order to feed that to the Write to Spreadhsheet File VI:
    You'll need to check on the transpose. Note that doing this will lose the timing information. You may want to use the Write LabVIEW Measurement File Express VI instead.
    Also, any reason why you have a loop set to run just once?
    Message Edited by smercurio_fc on 03-19-2008 03:16 PM
    Attachments:
    save 2D.png ‏3 KB

  • Array of cluster to array of element - or - Cluster of arrays?

    Hi all,
    I have a large cluster (lets call it C_data) containing measured data e.g. 10 Temperatures, Pressure, (Temp_1, ...).....
    All these data are measured once per second. I now collect all data
    measured over a certain time in an array of the aforementioned cluster,
    that is
    an array of C_data. In order to display time series of data in graphs I
    need to extract arrays of elements from this array of C_data.
    In a text based programming language this could look like the following:
    Struct C_data {Temp_1, Temp_2, P_1.....}
    ar_C_data is an array of C_data
    now I want to do something like:
    array_of_Temp_1 = ar_C_data[*].Temp_1
    In some programming languages this works but I cannot unbundle_by_name the array of Temp_1 from ar_data in Labview.
    Since my cluster is large and may change in structure (for this reason I use a typedef) a generic solution would be the best.
    I know that I could: loop over all elements of ar_C_data, unbundle by
    name, index elements into arrays, and use these but this seems very
    inefficient if it is done every second on a large cluster (30 elements) with several thousand array elements....
    Olaf

    You can minimize the overhead of scanning through all elements and extracting if you pre-define the array and use "replace array subset".  This avoide having to re-size the array which is costly.
    Or you can keep an array separately in memory.  When one cluster element is added, the corresponding element is added to the array too.  Causes some memory overhead, but you're going to have that anyway if you generate them "on the fly".
    I don't see a way to do this other than either search through the array and pick the elements you need -or-
    keep a copy of the data in a form you can use.
    It's a common question of how to structure data to best suit two sometimes conflicting needs - efficiency and useability.
    What might be of interest is to change the "Array" - "Cluster" order and have a single cluster C-Data with arrays of each element required.  Might be a bit more difficult to use, it depends on your application.
    This way you have all arrays ready at all times, but generating a single cluster requires bundling the individual units on the fly.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • I need a tutor in order to pass my class in Java Programming!

    I'm having a lot of trouble keeping up in my online course. Because there is no class room, I find it difficult to ask questions. The time lap between question and answer makes it extra difficult to concentrate and stay focused on the problem. I would really like someone to be my tutor. Corresponde via email so that I can get help quicker and stay on track.
    I'm suppose to write an array in order to keep inventory. I have no idea where to even start. Here is the assignment, if you can help me and point me in the right direction, or show an example of codes I can use, it would be greatly appreciated.
    1) Create a product class that holds the item number, the name of the product, the number of unites in stock, and the price of each unit.
    Item # 1, Red Hanging Candle Holder, 24, $12.00
    Item # 2, Blue Hanging Candle Holder, 24, $12.00
    Item # 3, Green Hanging Candle Holder, 24, $12.00
    Item # 4, Yellow Hanging Candle Holder, 24, $12.00
    2) Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit).

    God bless, Darryl. My time is more valuable to me.
    Maybe this arrangement works because you need the
    instruction as much as the OP does. The only
    question is: who will provide it? If neither person
    knows more than a month's worth of Java, how is new
    information brought in?
    Thanks duffymo for your blessing. As programming is just a hobby for me -- since 1983 -- I agree that my time is (much much) less valuable than yours. And yes, I expect the learning process to be mutually beneficial. And while I don't plan to make my living off java, I believe in doing things correctly or not at all. My one month experience in Java is backed up by programming in more languages than most professionals use in a lifetime, on platforms starting from pre-DOS systems with CTDs and a single-line display through DOS, xenix, PDP-11, MicroVAX and every version of Windows from 95 onwards.
    In any case, don't you think it would help if the simplest of questions were kept off these forums and solved in mutual self-help groups? some of whose members had nore time than others to spend on Googling and searching the forums? The first benefit would be to those who have progressed beyond the obvious, as you seniors would have more time to answer their pleas for help instead of getting bogged down in badly or unformatted code with all the trappings of cut-n-paste, meaningless comments that seem to be intended more for the teachers than the learners -- I could go on and on.
    I apologise for what I'm about to do; I do really agree with the general feeling on the forums that OPs benefit much more from being guided towards their goal than from being spoonfed a code that works. But I would really appreciate your critique of this code, which is my first console application. It took about half an hour, including Googling. I am aware that there are absolutely no comments, and the output columns don't line up, due to my as yet inadequate knowledge of output formatting. Anything else you can point out would help me in my learning process.
    Thanks for your time, Darryl
    File Inventory.javapublic class Inventory
        public static void main (String args [])
            int[] itemNumbers   = { 1,
                                    2,
                                    3,
                                    4
            String[] itemNames  = { "Red Hanging Candle Holder",
                                    "Blue Hanging Candle Holder",
                                    "Green Hanging Candle Holder",
                                    "Yellow Hanging Candle Holder"
            int[] unitsInStocks = { 24,
                                    24,
                                    24,
                                    24
            double[] unitPrices = { 12.0,
                                    12.0,
                                    12.0,
                                    12.0
            Product[] products = new Product[4];
            for ( int i = 0; i < products.length; i++)
                products[i] = new Product(itemNumbers,
    itemNames[i],
    unitsInStocks[i],
    unitPrices[i]);
    double productValue = 0.0;
    double totalValue = 0.0;
    System.out.println("Item #\t" +
    "Name\t" +
    "Units in stock\t" +
    "Unit price\t" +
    "Total Cost");
    for ( int i = 0; i < products.length; i++)
    productValue = products[i].get_productValue();
    totalValue = totalValue + productValue;
    System.out.println(products[i].get_productDetails() + "\t" +
    Double.toString(productValue));
    System.out.println("");
    System.out.println("\t" +
    "\t" +
    "\t" +
    "Grand Total\t" +
    Double.toString(totalValue));
    File Product.javapublic class Product {
        private int itemNumber;
        private String itemName;
        private int unitsInStock;
        private double unitPrice;
        private Product()
        public Product(int    itemNumberIn,
                       String itemNameIn,
                       int    unitsInStockIn,
                       double unitPriceIn)
            itemNumber   = itemNumberIn;
            itemName     = itemNameIn;
            unitsInStock = unitsInStockIn;
            unitPrice    = unitPriceIn;
        public double get_productValue()
            double unitValue = (double) unitsInStock * unitPrice;
            return unitValue;
        public String get_productDetails()
            String productDetails = Integer.toString(itemNumber) + "\t" +
                                    itemName + "\t" +
                                    Integer.toString(unitsInStock) + "\t" +
                                    Double.toString(unitPrice);
            return productDetails;
    }The forum software seems to have reduced my indentation by 1 space in many lines, they line up correctly in Notepad.
    Message was edited by:
    Darryl.Burke

  • Add_item : Attributes list collection sort order

    Hello:
    I created multiple custom attributes and added them to my custom item type. I need to apply these attributes while adding an item programmatically.
    1) How do i define the order of the Attributes list via the Portal builder so as to match the corresponding values read from a list/table,etc. ?
    2) The ordering arrow buttons in the attribute list of my custom item type does not match the result set from my query. I tried all options of "order by" clause. Here is the query - (componenttype is the name of my custom item type)
    select iatts.ID
    ,atts.caid
         ,atts.DATA_TYPE     
         ,atts.CAID
         ,atts.NAME,atts.DISPLAY_NAME
         ,iatts.ITEM_TYPE_ID
    from wwsbr_item_types itypes
    ,wwsbr_item_type_attributes iatts
    ,wwsbr_attributes atts
    where --itypes.caid = 133
    itypes.name like 'ComponentType'
    and itypes.ID = iatts.ITEM_TYPE_ID
    and iatts.ATTRIBUTE_ID = atts.ID
    --and atts.CAID = 133
    order by atts.id
    3) I need to expect a certain order of the attribute ids, when bulk collecting into the attributes array, in order to populate the values collection in the same. So, how do I determine the order of the attributes ids ?
    4) Is there a better way to do this ?
    Thank You.
    regards
    Ananth

    Document Sets are great tools for grouping multiple documents together. However, if every set has exactly one document, it would be better to just upload the file and not place it within a Document Set:
    Uploading documents using object model - http://msdn.microsoft.com/en-us/library/office/ms454491(v=office.14).aspx
    Uploading documents using web services -
    http://cecildt.blogspot.com/2010/10/upload-documents-to-sharepoint-2010.html
    If you have requirements to use Document Sets, keep in mind that this adds a layer of complexity beyond a simple Document Library. Behind the scenes, each Document Set is treated as a separate folder, and although can you query items within it, there might
    be extra steps for getting the sort order to ignore the folder structure. Can you try setting the Scope to be "Recursive" and also specify that you are looking only for files and not folders:
    <Eq><FieldRef Name='FSObjType'/><Value Type='Lookup'>1</Value></Eq></Where>
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Javascript array

    I am trying to create a page where the user can click on a
    thumbnail image and it will come up in the larger photo area so
    that they can see a larger version of the image. I have created
    some javascript but am not sure if I need to add splashCaption
    splashImage Arrays in order for it to work. I also want to have the
    text linked to each array. I want to do this so that I don't have
    to create seperate pages for each large photo
    (ie...ipug_green.html, ipug_red.html, etc).
    Here is what the page (ipug.html) looks like:
    http://homepage.mac.com/coasterlisa/daisys_corner/ipug.html.
    The javascript isn't working probably because the arrays aren't
    coded in and the text needs something different (behaviors?)added
    to it.
    Any help would be appreciated.
    Note: I realize from reading the book I was writing the
    scripting from (DW MX 2004 - Grannell/Powers/McLachlan) that some
    browsers and users won't have access to this script format. So, I
    was wondering if there was another way where the user can click on
    a thumbnail and see the larger image color without starting at the
    top of each page. I tried anchor tags and got a little confused
    working with seperate HTML pages (ipug2.html, ipug3.html,
    ipug4.html, etc). I am also using DW 8 so I'm sure if this
    scripting code is still workable.

    Please show us a link to the page or at least post the code.
    "CoasterLisa" <[email protected]> wrote in
    message
    news:er880v$crq$[email protected]..
    >I am trying to create a page where the user can click on
    a thumbnail image
    >and
    > it will come up in the larger photo area so that they
    can see a larger
    > version
    > of the image. I have created some javascript but am not
    sure if I need to
    > add
    > splashCaption splashImage Arrays in order for it to
    work. I also want to
    > have
    > the text linked to each array. I want to do this so that
    I don't have to
    > create
    > seperate pages for each large photo
    (ie...ipug_green.html, ipug_red.html,
    > etc).
    >
    > Here is what the page (ipug.html) looks like. The
    javascript isn't working
    > probably because the arrays aren't coded in and the text
    needs something
    > different added to it.
    >
    > Any help would be appreciated.
    >
    > Note: I realize from reading the book I was writing the
    scripting from (DW
    > MX
    > 2004 - Grannell/Powers/McLachlan) that some browsers and
    users won't have
    > access to this script format. So, I was wondering if
    there was another way
    > where the user can click on a thumbnail and see the
    larger image color
    > without
    > starting at the top of each page. I tried anchor tags
    and got a little
    > confused
    > working with seperate HTML pages (ipug2.html,
    ipug3.html, ipug4.html,
    > etc). I
    > am also using DW 8 so I'm sure if this scripting code is
    still workable.
    >

  • Tokens and arrays

    hello, I need help with the following. I have broken contents of file into tokens, and now I want to load those tokens into arrays and display the contents of the arrays. How do i do this?
    The name of the file is testing.txt with the following three lines;
    Hey your world!
    beware of mortgage fraud.
    Research before you buy!
    my code is as follows;
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.*;
    public class Test{
         public static void main(String[] args){
              try{
                   //collect a file path / name from the user
                   System.out.println( " Enter the filepath for loading" );
                   Scanner myScanner = new Scanner(System.in);
                   String fileName = myScanner.next();
                   //load the contents of that file into a bufferedreader
                   FileReader myFR = new FileReader(fileName);
                   BufferedReader myBR = new BufferedReader(myFR);
                   String line = " ";
                   StringTokenizer words;
                   String word = " ";
                   System.out.println("Here are the lines in the file ");
                   System.out.println(" ");
                   //loop through the lines of the document (which method reads lines?)
                   //main loop repeats until there are no more line
                   while((line = myBR.readLine())!=null)
                   {System.out.println(" The line is ");
                        System.out.println(line);
                           //line = myBR.readLine();
                        System.out.println("");
                        System.out.println( " Broken like a token ");
                        System.out.println( "");
                   ////break each line into tokens,
                      words = new StringTokenizer(line);
                      ////loop through the tokens, process each word in the line
                      while(words.hasMoreTokens()){
                        word = words.nextToken();
                        System.out.println(word);
                   //end while
                   //load each token into an array
                   String wordAry [] = new String[11];
                   //loop through the array and present each token to the user          
                        for(int index=0; index<13; index++){      
                   System.out.println(wordAry[index]);
                   System.out.println("");
              System.out.println(" The Contents of array Results " );
              }catch(FileNotFoundException e){
                   System.out.println("File could not be found or opened");
              }catch(IOException e){
                   System.out.println("Error reading file");
              }// end catch
         }//end main
    }//end class

    Well you've definitely created an array...but you never put anything in it. You have to actually put something IN the array in order to get it out later. Also, your array is size 11, meaning the indexes go from 0 to 10. But your print loop goes from 0 to 12, so you'll get an out of bounds exception.
    If you don't understand array basics, read the tutorial: [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html]

  • In the attached vi, I have a 2-dim series of EMGs which I would like to connect with a 1-dim array. How can I do this?

    In the attached vi, de Y values are given for each time as a matrix. The problem is that the y values coming out have to be a 1-dim array, in order to connect this vi with another vi. How can I do this?
    Attachments:
    3-dim_Filter.vi ‏48 KB

    Hi,
    can you post your curve fitting .vi?
    I think you can do this with the reshape array.vi, and take the 2-D array, find out it's size, and multiply the two dimensions together to get the number of elements you need. That'll give you the array as 1-D, but whether it's in the correct order as you need it is another matter.
    It all depends on what the 2-D array is representing, and how much of it needs to go to the "other" .vi
    Hope that helps
    S.
    // it takes almost no time to rate an answer

  • Turtle simulation using array

    Hi,
    I am working on a problem that simulates a turtle, walking around a room. The turtle holds a pen in one of two positions - up or down. When the pen is down the turtle traces out shapes as it moves, while when the pen is up the turtle is just walking without "drawing" anything.
    I have to use 20 x 20 array, called floor that represents the floor and is initialized to zeros. I am reading commands from an array that contains them. These commands basically "direct" the turtle how to move. I have to keep track of the current position of the turtle at all times and whether the pen is up or down. We assume the turtle always starts at position (0,0) with the pen up.
    Suppose the turtle is near the center of the floor. The "program" shown below would draw and print 12 x 12 square and leaving the pen in up position:
    2
    5, 12
    3
    5, 12
    3
    5, 12
    3
    5, 12
    1
    6
    9
    considering that
    1 - Pen up
    2 - Pen down
    3 - Turn right
    4 - Turn left
    5, 10 - Move forward 10 spaces (in my case it is 12 spaces)
    6 - Display the 20 x 20 array representing the floor
    9 - End of data (sentinel)
    As the turtle is moving with the pen down, set the appropriate elements of the array floor to 1. When command 6 is reached (to display the array) wherever there is 1 in the array display an asterisk. Wherever there is 0, display blank.
    public class TurtleGraphics {
         private int floor[][] = new int [20][20];
         private int commandsToTurtle[] = {2, 5, 12, 3, 5, 12, 3, 5, 12, 3, 5, 12, 1, 6, 9};
         private int flagPen = 1, positionsToMove = 0, numberElements = 0, flagPosition = 0;
         void moveTurtle(){
              for(int value: commandsToTurtle){
                   numberElements++;
                    // I use this array in order to keep track of the values past command 5
              boolean positionsTrack[] = new boolean[numberElements];
              for(int value: commandsToTurtle){
                   switch(value){
                   case 1:
                                    //  I thought to use this flag somehow but haven't figured out
                                    //yet how exactly
                        flagPen = 1;  
                        break;
                   case 2:
                                     //  Same with this one
                        flagPen = 2;  
                        break;
                   case 3:
                   case 4:
                   case 5:
                        for(int i = 0; i < commandsToTurtle.length; i++){
                         // If command 5 is reached
                             if(commandsToTurtle[i] == 5 && flagPosition == 0){   
                        //  I set the appropriate element of the boolean array to true
                                  positionsTrack[i + 1] = true;                
                        for(int i = 0; i < positionsTrack.length; i++){
                   //  If given element of the boolean array is not false use its position
                   // with the array that holds the command numbers. That way I am getting how many
                   //  positions the turtle has to move
                             if(positionsTrack[i] != false){                 
                                     positionsToMove = commandsToTurtle;
                                  positionsTrack[i] = false;
    // Controls not to re-set the boolean array
                                  flagPosition = 1;
                                  break;
                        move(positionsToMove);
                        break;
                   case 6:
                        for(int row = 0; row < floor.length; row++){
                             for(int column = 0; column < floor[row].length; column++){
                                  if(floor[row][column] == 1)
                                       System.out.print('*');
                                  else
                                       System.out.print(' ');
                             System.out.println();
                        break;
         void move(int number){
    So far I've done the part to get how many positions the turtle has to move plus the display part ( command 6 ) .
    Now I am stuck.
    Anybody has any ideas how exactly to implement the "moving" of the turtle ( going forward, turning left / right ) or to implement the current position?
    Any help is greatly appreciated. Thanks in advance.
    P.S. Does anybody know how I can make the window with the code not to be so wide?
    Edited by: blias on Dec 20, 2010 10:56 PM

    almightywiz wrote:
    But aren't you already doing something very similar? In all of your other loops?
    All your "turtle" is is just an index pointing to a location in an array. So how would you move an index to point at the various array locations? (Hint: see my second question)
    For example, let's say you have a 1-dimensional array:
    int[] x = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};How would you print each value in the array, along with the index in the array the value resides at.
    So, using the array x, how would you get the following output:
    10 - 0
    9 - 1
    8 - 2
    7 - 3
    6 - 4
    5 - 5
    4 - 6
    3 - 7
    2 - 8
    1 - 9
    I wasn't able to reply earlier.
    for(int i = 0; i < x.length; i++){
         System.out.printf("%d - %d\n", x, i);

  • Dynamic string array

    I need to make a dynamic string array.
    Deeper explanation:
    I am trying to use a FOR loop to send a series of commands to an 8-channel device.  Each channel requires 7 (actually, 1/2 need only 5, the other 1/2 need 7) strings to set them up and the entire sequence needs to be performed 8 times.  I started a test .vi by simply using a constant array of type sting.  I can sequentially pick each string and program my device perfectly.  Now I'd like to do things like add the channel # somewhere in the mix, use variable values based on other controls in my .vi to set the parameters of the channel.
    EXAMPLE:
    The user sets certain values that determine delays and width for an 8-channel DDG (Digital Delay Generator, to some, a pulse generator).  These values then need to be loaded into the DDG.  The Strings will look something like this:
    ULSE1TATE 1
    ULSE1:WIDTH 0.009 000           *NOTEpaces behind decimal are for better viewability only
    ULSE1ELAY 0.000 000
    ULSE1YNC T0
    ULSE1:CMODE DUTY
    ULSE1COUNTER 1
    ULSE1:BCOUNTER 1
    ULSE2TATE 1
    ULSE2:WIDTH 0.000 300
    ULSE2ELAY 0.008 700
    ULSE2YNC T0
    ULSE2:CMODE NORMAL
    So widith and delay params change, the pulse# changes, and whether it's on certain channels decides if the mode is duty or normal and duty comes with the subsequent params pcount and bcount.
    help?
    PS - I am going to move the state, sync, and cmode to a common, initialize loop run only at program start, but I still need to use width, delay, and (variably) pcount and bcount.
    PPS - I am trying to edit post to diable smilies.  Commands should read:"colon, P (or D)" not ,
    PPPS - Success, at least for me.  I disabled smilies in my settings, I don't know if that means my posts won't show smilies or if just what I am looking at won't show smilies, any responders let me know how it's showing for you.
    Message Edited by Radiance_Jon on 07-16-2007 01:48 PM
    Message Edited by Radiance_Jon on 07-16-2007 01:52 PM

    smercurio_fc wrote:
    Well, in my experience I have found that dealing with errors early on is the best course of action as it leads to less headaches down the road...
    Auto-indexing is one of the more powerful features of LabVIEW. If you're familiar with text-based languages it's equivalent to the "foreach" statement. Basically it allows you to wire an array into a for-loop and the size of the array tells LabVIEW how many times the loop needs to execute. Inside the loop LabVIEW peels of each element of the array in order for each iteration of the loop. Looks like this:
    My comment regarding not needing the sequence frame was related to using the error cluster since that wire would allow you enforce data dependency like so:
    Note that the VISA resource wire does the same thing.
    "I got a little aggravated at how NI seemed to handle the loops in those two frames concurrently".  That's because LabVIEW is a data-flow language, and not a sequenced language like C or VB. In fact, that's one of the things that makes LabVIEW so powerful.
    Message Edited by smercurio_fc on 07-16-2007 04:48 PM
    MAN!  I KNEW that!!!!  GGRRRRR!!!  That makes sense.  Actually that's WHY I connected the error lines in the first place was to aide in flow control.  OH!!!  Still getting used to LabVIEW. 
    But I still have a question related to flow control.  Check out the pic below.  LabVIEW runs everything in a seemingly random order... well at least where it STARTS each chain of data.  It obviously starts with the static constants or the earliest data in each chain, but I can't figure out how in the world it's deciding WHICH chain to start first.  It kind of seems to go with the lower right and work it's way to top-left, but it doesn't exactly do that either.  I dunno if it's worth you answering this concern or not, but if you got one for me I'd be much obliged. 
    I should take a LabVIEW class!  Yeah right, as if they'd let me... R&D means I won't need it tomorrow ;( which stinks cause I'm liking LabVIEW the more I learn it.  (I was not fond of it in the beginning, but that was my stubborness). 
    thanks again so much for all your help!!!!
    Also, I am using all those strings to make my display appear as I want it to... I wonder if there is another way?  I am aware of system labels, but I like the look of the recessed, grayed control boxes better.
    Message Edited by Radiance_Jon on 07-16-2007 05:06 PM

Maybe you are looking for

  • Query on interface

    I am getting "The parameter name [startDate] in the query's selection criteria does not match any parameter name defined in the query" error when querying on interface using TopLink 11g (11.1.3). The interface is implemented by many classes MyImpleme

  • Does anyone know how to save a file in CC 10.0 or higher that is viewable in CC 9.2?

    I am trying to make my fiels viewable to someone who has Adobe CC version 9.2, but I have version 10.0. Does anyone know how to save my files so the are readable?

  • Copy all assets in a production out to a device

    I have been trying to set-up an approve process where once an editor sets production status to approved - all assets within the production should copy out to a device which is a dropfolder for signiant. But I get an error stating "Security Restrictio

  • CONTROL DATA FOR ACTIVITY TYPE NOT MAINTAINED

    dear all i get this error when calculating production order cost control data for activity type 1000\4230\1420 not maintained for fiscal year 2007 i hv maintained data in kp26 can any one pl help. i am learnign sap pp and hv 4.7 version thanks and re

  • Can't find my LaCie BigDisc!

    Accidently pulled the powercord for my BigDisc with a huge project on it and now the computer will not mount it on the desktop. Desperate for help on what to do. Are there any tools to find it again or am I screwed? I'm on Os X 1.3.9