Compair two array elements

hi
Friends
i am compairing two int arrays of different size & printing the common elements of the both arrays
for example.----
int a[]=a{12,34,56,2,4,5,6,7,8,9,0,6,54,4,3,2,3,5,76,43,78,78,54,32,5,6,44,32};
int b[]=b{11,2,32,45,61,78,34,25,4};
i want output array having elements common to both
int c[]={ 2,32,78,34,4};
& count how many nos are matched
please help me
thanks
shivanand

Noone will do it for you, but if you post your code we can help.
You may need to use nested for loops, one to iterate over the first array, then the inner one to iterate over the second array. Make a third array that is as big as your smallest array (or better make a java.util.Set instead) and add any values that are duplicates into that.

Similar Messages

  • Find Intersection of two array elements in Oracle 9i

    How to find intersection of two arrays in pl/sql for Oracle 9i.
    it is feasible in 11g using given code but this code is not working in 9i please help....
    DECLARE
    abc LIST := list(1,2,3,4);
    def LIST := list(4,5,6,7);
    BEGIN
    dbms_output.put_line(format_list(abc MULTISET EXCEPT def));
    END;
    Thanks in advance.... :)

    Argh. Never mind. My coordinates were reversed.
    People that made my data set specified the coordinates as lat/long and I didn't question it. I can now see that Oracle expects long/lat instead, so my example works now.

  • Combining two StringBuffer array elements into a single array element

    I just need to know how to combine two stringBuffer array elements into one
    StringBuffer ciphertext [] = new StringBuffer[2];
              StringBuffer s0 = new StringBuffer("11011111111110001001101110110101");
              StringBuffer s1 = new StringBuffer("00010011001101000101011101111001");
              ciphertext[0] = s0;
              ciphertext[1] = s1;
              ciphertext[2] = ciphertext[0].append(ciphertext[1]);I get an array index out of bounds exception:2
    Thanks

    StringBuffer ciphertext [] = new StringBuffer[3];  // legal index values are: 0,1,2

  • Can;t find what is wrong. Trying to add elements in two arrays

    Hello everyone
    I'm trying to take as input two numbers, convert them to arrays and add all the element of the array one by one. I want the result to be the sum of every element of the array. Let's say array1={1,2,3,4} and array2={2,6,4,3} I want the final result to be 3877.
    If the sum of one element of the array is greater than nine, then I would put zero and add 1 to the element on the left.
    Here is the code:
    import javax.swing.JOptionPane;
    public class Main {
        public static void main(String[] args) {
            String numberOne = JOptionPane.showInputDialog
                                    ("Enter the first number: ");
         String numberTwo = JOptionPane.showInputDialog
                                    ("Enter the second number: ");
            //compare string length and make them equal length
            int[]n1 = toArray(numberOne); // my first array
         int[]n2 = toArray(numberTwo); // my second array
         //call the method that ads both strings
         int[]finalArray = arrSum(n1,n2);
           JOptionPane.showMessageDialog(null, "The sum of the two numbers is: "
                   + finalArray);
        }//end of main
        //method to create an array from a string
        public static int[] toArray(String str)
                int[]arr = new int[str.length()];
                arr[0]=0;
                for (int i=1; i<str.length(); i++)
              arr= Character.digit(str.charAt(i),10);
    return arr;
    }//end of toArray
    //method to add arrays by elements
    public static int[]arrSum (int[]arr1, int[]arr2){
    for (int i = arr1.length-1; i >=1; i--)
    int sum = arr1[i] + arr2[i];
    if (sum > 9)
              { sum -= 10;
              arr1[i-1]++;
    return arr1;
    }//end of arrSum method
    }Edited by: designbc01 on Feb 16, 2010 1:15 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    The best advice I can give you is to break your problem up into smaller pieces. First, focus on a method that converts an input String into an array. When you have that working perfectly, then focus on creating a method that "adds" two arrays with the logic you described. When you have that working perfectly, then combine the two different pieces.
    Why does your for loop in toArray( ) start with 1? The first index of a String, array, or pretty much anything else, is zero.

  • Printing every possible pair combination of elements in two arrays??

    Hi there,
    I'm trying to implement the problem of printing every possible pair combination of elements in two arrays. The pattern I have in mind is very simple, I just don't know how to implement it. Here's an example:
    g[3] = {'A', 'B', 'C'}
    h[3] = {1, 2, 3}
    ...code...??
    Expected Output:
    A = 1
    B = 2
    C = 3
    A = 1
    B = 3
    C = 2
    A = 2
    B = 1
    C = 3
    A = 2
    B = 3
    C = 1
    A = 3
    B = 1
    C = 2
    A = 3
    B = 2
    C = 1
    The code should work for any array size, as long as both arrays are the same size. Anybody know how to code this??
    Cheers,
    Sean

    not a big fan of Java recursion, unless tail recursion, otherwise you are bound to have out of stack error. Here is some generic permutation method I wrote a while back:
    It is generic enough, should serve your purpose.
    * The method returns all permutations of given objects.  The input array is a two-dimensionary, with the 1st dimension being
    * the number of buckets (or distributions), and the 2nd dimension contains all possible items for each of the buckets.
    * When constructing the actual all permutations, the following logic is used:
    * take the following example:
    * 1    2    3
    * a    d    f
    * b    e    g
    * c
    * has 3 buckets (distributions): 1st one has 3 items, 2nd has 2 items and 3rd has 2 items as well.
    * All possible permutaions are:
    * a    d    f
    * a    d    g
    * a    e    f
    * a    e    g
    * b    d    f
    * b    d    g
    * b    e    f
    * b    e    g
    * c    d    f
    * c    d    g
    * c    e    f
    * c    e    g
    * You can see the pattern, every possiblity of 3rd bucket is repeated once, every possiblity of 2nd bucket is repeated twice,
    * and that of 1st is 4.  The number of repetition has a pattern to it, ie: the multiplication of permutation of all the
    * args after the current one.
    * Therefore: 1st bucket has 2*2 = 4 repetition, 2nd has 2*1 = 2 repetition while 3rd being the last one only has 1.
    * The method returns another two-dimensional array, with the 1st dimension represent the number of permutations, and the 2nd
    * dimension being the actual permutation.
    * Note that this method does not purposely filter out duplicated items in each of given buckets in the items, therefore, if
    * is any duplicates, then the output permutations will contain duplicates as well.  If filtering is needed, use
    * filterDuplicates(Obejct[][] items) first before calling this method.
    public static Object[][] returnPermutation(Object[][] items)
         int numberOfPermutations = 1;
         int i;
         int repeatNum = 1;
         int m = 0;
         for(i=0;i<items.length;i++)
              numberOfPermutations = numberOfPermutations * items.length;
         int[] dimension = {numberOfPermutations, items.length};
         Object[][] out = (Object[][])Array.newInstance(items.getClass().getComponentType().getComponentType(), dimension);
         for(i=(items.length-1);i>=0;i--)
              m = 0;
              while(m<numberOfPermutations)
                   for(int k=0;k<items[i].length;k++)
                        for(int l=0;l<repeatNum;l++)
                             out[m][i] = items[i][k];
                             m++;
              repeatNum = repeatNum*items[i].length;
         return out;
    /* This method will filter out any duplicate object in each bucket of the items
    public static Object[][] filterDuplicates(Object[][] items)
         int i;
         Class objectClassType = items.getClass().getComponentType().getComponentType();
         HashSet filter = new HashSet();
         int[] dimension = {items.length, 0};
         Object[][] out = (Object[][])Array.newInstance(objectClassType, dimension);
         for(i=0;i<items.length;i++)
              filter.addAll(Arrays.asList(items[i]));
              out[i] = filter.toArray((Object[])Array.newInstance(objectClassType, filter.size()));
              filter.clear();
         return out;

  • Sort two dimentional array element

    Hi,
    i want sort 2dimentional array element ,
    suppose i have matrix like this
    [ 5,2,6]
    [ 3,1,9]
    [8,7,2]
    then i want to answer like that
    [ 1,2,2]
    [3,5,6]
    [7,8,9]

    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    [How To Get Good Answers To Your Questions|http://www.tek-tips.com/viewthread.cfm?qid=473997]
    db

  • About combing two array into one

    Hi all,
      I post a questiona bout converting an array of integer into char (byte) array and I got a solution already http://forums.ni.com/t5/LabVIEW/how-to-display-char-code-properly/m-p/2596087#M780368
    However, I enouther another problem while dealing with an array of  U16 type. I would like to extract the high and low byte from numbers (U16) stored in array. I extract the high and low byte for each U16 number and convert them as char, concatenate them to a string. Repeat this process for each element in the array so to get a big string with each element is a char for high and low byte. My code is enclosed as follows
    It works fine but I am concerning the speed. Is that any other way to do it fast and don't use loop (in real case, I will deal with pretty big array many times, efficiency is a problem). Note that the high and low bytes array extracted from the original array with the module Split number.vi, but how can I combine these two array in one code with data arranged as high-low-high-low ... ? Thanks.
    Solved!
    Go to Solution.

    PKIM wrote:
    However, I enouther another problem while dealing with an array of  U16 type. I would like to extract the high and low byte from numbers (U16) stored in array. I extract the high and low byte for each U16 number and convert them as char, concatenate them to a string. Repeat this process for each element in the array so to get a big string with each element is a char for high and low byte. My code is enclosed as follows
    It works fine but I am concerning the speed. Is that any other way to do it fast and don't use loop (in real case, I will deal with pretty big array many times, efficiency is a problem). Note that the high and low bytes array extracted from the original array with the module Split number.vi, but how can I combine these two array in one code with data arranged as high-low-high-low ... ? Thanks.
    You need to be more clear.
    Looking at the code, you are dealing with I16, not U16. Also your index array primitives could be replaced by autoindexing. Your use of the feedback node only makes sense if you want to append strings forever with stale data, thus growing data structures without limits. If you only want to convert the current data, remove the feedback mode and use a "concatenate strings" with a single input. A for loop is one of the most efficient data structures and using it is not a problem. One way or another the code needs top oerate on all data.
    All that said, I agree with Tim that most likely all you need to do is insert a typecast after the "to I16" and eliminate all other code.
    LabVIEW Champion . Do more with less code and in less time .

  • Two array objects compareTo:

    Have two arrays: ttt and ppp. I have to have a method to compare them.
    public int compareTo(object ob)
    both of the arrays are int type and both have super long numbers in them.
    Thanks

    Actually, the reflection api is pretty fast since
    JDK1.4.0...No. Reflection could not be fast. In J2SDK1.4 it seems to be faster then in previous releases. But improvments do not include array operations. So here are some results of simple benchmark:
    bash-2.05a$ /usr/java/jdk1.3.1_04/bin/java TestArray
    Result for reflect copiing (3 elements, 1000000 times): 4915ms
    Result for system copiing (3 elements, 1000000 times): 460ms
    Result for pure java copiing (3 elements, 1000000 times): 137ms
    bash-2.05a$
    bash-2.05a$ /usr/java/j2sdk1.4.0_01/bin/java TestArray
    Result for reflect copiing (3 elements, 1000000 times): 6082ms
    Result for system copiing (3 elements, 1000000 times): 491ms
    Result for pure java copiing (3 elements, 1000000 times): 115ms
    bash-2.05a$
    bash-2.05a$ /usr/java/j2sdk1.4.1/bin/java TestArray
    Result for reflect copiing (3 elements, 1000000 times): 5738ms
    Result for system copiing (3 elements, 1000000 times): 497ms
    Result for pure java copiing (3 elements, 1000000 times): 157ms
    bash-2.05a$
    As you can see, in new Java reflect operations on arrays are even slower then in jdk1.3.1. System copiing is good alternative for pure java (element by element) copiing, espetially for big arrays. And here is the code of this benchmark, test it on your PC also:
    import java.lang.reflect.*;
    public class TestArray {
        static void doNothing(){}
        static int field;
        public static void main(String[] args) throws Exception {
            final int COUNT = 3, TIMES = 1000*1000;
            final String[] arr1 = new String[COUNT];
            final String[] arr2 = new String[COUNT];
                long time = -System.currentTimeMillis();
                for(int i=TIMES; i-->0;)
                    copyReflect(arr1, arr2, COUNT);
                time += System.currentTimeMillis();
                System.out.println("Result for reflect copiing ("+COUNT+" elements, "+TIMES+" times): "+time+"ms");
                long time = -System.currentTimeMillis();
                for(int i=TIMES; i-->0;)
                    copySystem(arr1, arr2, COUNT);
                time += System.currentTimeMillis();
                System.out.println("Result for system copiing ("+COUNT+" elements, "+TIMES+" times): "+time+"ms");
                long time = -System.currentTimeMillis();
                for(int i=TIMES; i-->0;)
                    copyPureJava(arr1, arr2, COUNT);
                time += System.currentTimeMillis();
                System.out.println("Result for pure java copiing ("+COUNT+" elements, "+TIMES+" times): "+time+"ms");
        private static void copyReflect(Object src, Object dst, int count) {
            for(int i=count; i-->0; ) Array.set(dst, i, Array.get(src, i));
        private static void copySystem(Object src, Object dst, int count) {
            System.arraycopy(src, 0, dst, 0, count);
        private static void copyPureJava(String[] src, String[] dst, int count) {
            for(int i=count; i-->0; ) dst[i] = src;

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • User defined func: Unavble to merge two arrays in result list

    Hi
    I am trying to merge two arrays on the basis of "FEE" element in the input file;
    Actually there is an Attribute Name and Value pair array coming in the input file which has 5 pairs already(Notification + 100 , oversize + 8 etc.) see example below;
    <m0:Fees>ZB9</m0:Fees>
    <m:Attribute>
      <m0:Attributename>NOTIFICATION</m0:Attributename>
      <m0:Attributevalue>100</m0:Attributevalue>
      </m:Attribute>
    <m:Attribute>
      <m0:Attributename>OVERSIZE</m0:Attributename>
      <m0:Attributevalue>8</m0:Attributevalue>
      </m:Attribute>
    <m:Attribute>
      <m0:Attributename>OVERWEIGHT</m0:Attributename>
      <m0:Attributevalue>108</m0:Attributevalue>
      </m:Attribute>
    <m:Attribute>
      <m0:Attributename>SIGNATURE</m0:Attributename>
      <m0:Attributevalue>294</m0:Attributevalue>
      </m:Attribute>
    <m:Attribute>
      <m0:Attributename>RTS</m0:Attributename>
      <m0:Attributevalue>8</m0:Attributevalue>
      </m:Attribute>
    The condition is:
    CASE 1. If the FEE doesn't exist in the file then only the Atrribute Name and Value in added to the Array
    CASE 2 If FEE exist then add all the Atrribute Name and Value pairs as well as in the last index of Array add String "Fee" in Attributename and String "ZB9" in  Attributevalue.
    CASE 1 is working fine.
    but in CASE 2 even if i m taking an output array of length Attributename +1 and Attributevalue +1 and trying to add "Fee" and "ZB9" respectively, it never happens.
    Please have a look at the code below;
       //write your code here
    public void ud_Attributename(String[] Fees,String[] Attributename,ResultList result,Container container){
              String attribute_copy[]=new String[Attributename.length+1];
              String attribute_name[]=new String[Attributename.length];
              String array_copy1[]=new String[Attributename.length+1];
              //int len =Attributename.length;
              if(Fees[0]!=null)
                   if(Fees[0].equals("ZB0"))
                   Fees[0]="01";
                   else if(Fees[0].equals("ZB5"))
                   Fees[0]="02";
                   else if(Fees[0].equals("ZB6"))
                   Fees[0]="03";
                   else if(Fees[0].equals("ZB9"))
                   Fees[0]="04";
              try{
                   if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04"))
                        for(int x=0;x<=Attributename.length;x++)
                             if(x==Attributename.length)
                             array_copy1[x]="Fee";
                             else{
                             array_copy1[x]=Attributename[x];
                             result.addValue(array_copy1[x]);
                   else
                        for(int i=0;i<=len;i++)
                             attribute_name<i>=Attributename[i+1];
                             result.addValue(attribute_name<i>);
              }catch(Exception e)
              {e.printStackTrace();}
    Same way i've used for Attributevalue.
    But the result is
    <ATTRIBUTEPAIR>
    <PAIR>
    <NAME>NOTIFICATION</NAME>
    <VALUE>04</VALUE>
    </PAIR>
    <PAIR>
    <NAME>OVERSIZE</NAME>
    <VALUE>8</VALUE>
    </PAIR>
    <PAIR>
    <NAME>OVERWEIGHT</NAME>
    <VALUE>108</VALUE>
    </PAIR>
    <PAIR>
    <NAME>SIGNATURE</NAME>
    <VALUE>294</VALUE>
    </PAIR>
    <PAIR>
    <NAME>RTS</NAME>
    <VALUE>8</VALUE>
    </PAIR>
    </ATTRIBUTEPAIR>
    Please suggest where i am wrong. ur help is very much appreciated.
    Thnks in advance

    this is i am doing now
       //write your code here
              String attribute_copy[]=new String[Attributename.length+1];
              String attribute_name[]=new String[Attributename.length];
              String attribute_name1[]={"Fee"};
              //String[] Attributename.copyTo(attribute_name1,0);
              //String[] attribute_name1 = (String[]) Attributename.Clone();
              //String fees;
              String array_copy1[]=new String[Attributename.length];
              int len =Attributename.length;
              for(int y=0;y<len;y++){
              array_copy1[y]=Attributename[y];
              if(Fees[0]!=null)
                   if(Fees[0].equals("ZB0"))
                   Fees[0]="01";
                   else if(Fees[0].equals("ZB5"))
                   Fees[0]="02";
                   else if(Fees[0].equals("ZB6"))
                   Fees[0]="03";
                   else if(Fees[0].equals("ZB9"))
                   Fees[0]="04";
                   else if(Fees[0].equals("ZA1"))
                   Fees[0]="05";
                   else if(Fees[0].equals("ZA2"))
                   Fees[0]="06";
              try{
                   if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04")||(Fees[0]=="05")||(Fees[0]=="06"))
                        int j=0;
                        for(int a=0;a<=len;a++)
                             if(j==0&&attribute_copy[j]==null)                                   
                                  attribute_copy[j]="Fee";
                             else
                                  //int b=-1;
                                  for(int i=0;i<=len;i++)
                                       if(i==j)
                                       //i=i-1;
                                       attribute_copy[j]=array_copy1[i-1];
                                       break;
                                       else{
                                       continue;}
                        result.addValue(attribute_copy[j]);
                        j+=1;
                   else
                        for(int i=0;i<=len;i++)
                             attribute_name<i>=Attributename[i+1];
                             result.addValue(attribute_name<i>);
              }catch(Exception e)
              {e.printStackTrace();}
    and the result in queue is
    SUPPRESS
    [FEE]
    [NOTIFICATION]
    [NOTIFICATION]
    [OVERSIZE]
    [OVERSIZE]
    [OVERWEIGHT]
    [OVERWEIGHT]
    [SIGNATURE]
    [SIGNATURE]
    [RTS]
    [RTS]
    but in the output i m getting
    <ATTRIBUTEPAIR>
    <REF_HANDLE>0001</REF_HANDLE>
    <PAIR>
    <NAME>Fee</NAME>
    <VALUE>04</VALUE>
    </PAIR>
    <PAIR>
    <NAME>OVERSIZE</NAME>
    <VALUE>8</VALUE>
    </PAIR>
    <PAIR>
    <NAME>OVERWEIGHT</NAME>
    <VALUE>108</VALUE>
    </PAIR>
    <PAIR>
    <NAME>SIGNATURE</NAME>
    <VALUE>294</VALUE>
    </PAIR>
    <PAIR>
    <NAME>RTS</NAME>
    <VALUE>8</VALUE>
    </PAIR>
    </ATTRIBUTEPAIR>
    Notification is missing.

  • Read part of an array element

    Hello All.
    As indicated in the title, I am trying to read part of an array element.
    What I'm doing is reading values from a LeCroy scope using a "write" than "read" I have returned the read values into an array but the issue is the scope returns a value "1, 52.33E-3"
    I simply want the element to be 52.33 that way I can use that for other calculations.
    For example my array is.
    "1, 34.334E-3"
    "1, 53.343E-3"
    "1, 143.232E-"
    And I want it to be
    34.334
    53.343
    143.232
    Thanks!
    Solved!
    Go to Solution.

    Another option is to use Spreadsheet String to Array and use the comma as the delimiter.  It can actually change your string into an array of numbers.  Then you just index out the number you want.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Unlimited number of array elements, help please!

    Hi everyone,
    I have written this code for comparing two arrays but i don't know how to accept all types array lengths. Now i am limited to 5 elements and i want it to accept the the users desired number of elements. How should i do?
    import java.util.*;
    class console
    public static void main (String[] args)
    ConsoleInput ci = new ConsoleInput();
              System.out.print("Hur m�nga Vektorer ska lagras? ");
              int antal = ci.readInt();
              if (antal<2)
             System.out.println("Du beh�ver 2 st vektorer");
             System.out.println("Hur m�nga element per vektor?");
             int antalelement = ci.readInt();
              System.out.println();
                   for (int j=0 ; j<antal-1; j++)
                   System.out.print("Ange vektor1: ");
                   int vektor = ci.readInt();
                   int vektor3 = ci.readInt();
                   int vektor2 = ci.readInt();
                   int vektor4 = ci.readInt();
                   int vektor5 = ci.readInt();
                   int[] vektor1 = new int[] {vektor,vektor3, vektor2, vektor4, vektor5};
                  int langd = vektor1.length;
                  System.out.print("Ange vektor2: ");
                   int element1 = ci.readInt();
                   int element2 = ci.readInt();
                   int element3 = ci.readInt();
                   int element4 = ci.readInt();
                   int element5 = ci.readInt();
                   int[] vektor21 = new int[] {element1,element2,element3, element4, element5};
                   Arrays.sort (vektor21);
                    int  kopiera = vektor1.length + vektor21.length;
                             int[] nyvektor = new int [kopiera];
                              for(int i = 0; i < vektor1.length; i++)
                                   nyvektor[i] = vektor1;
                             for(int i = 0; i < vektor21.length; i++)
                                  nyvektor[vektor1.length + i] = vektor21[i];
              System.out.print("Unionen ar: ");
                                  verktyg.sort(nyvektor);
                                  int counter = 0;
                                  for(int k = 1; k < nyvektor.length; k++)
                                  if(nyvektor[k] == nyvektor[k-1])
                                  counter++;
                                  int[] union = new int[nyvektor.length - counter];
                                  union[0] = nyvektor[0];
                                  int b = 1;
                                  for(int k = 1; k < nyvektor.length; k++)
                                  if(nyvektor[k] != nyvektor[k-1])
                                                           union[b] = nyvektor[k];
                                                           b++;
                                                           for (int h = 0; h<union.length; h++)
                                                           System.out.print(" " +union[h]);
    System.out.println();
    System.out.print("Intersection ar: ");
    Arrays.sort(nyvektor);
                   int counter1= 0;
              for(int i = 1; i < nyvektor.length; i++)
              if(nyvektor[i] == nyvektor[i-1])
              counter1++;
                   int[] intersection = new int[counter1];
              //c[0] = C[0];
              int a = 0;
              for(int i = 1; i < nyvektor.length; i++)
              if(nyvektor[i] == nyvektor[i-1])
                                       intersection[a] = nyvektor[i];
                                       a++;
                        for(int i=0; i<intersection.length; i++)
                                       System.out.print(" " +intersection[i]);
    System.out.println();
    System.out.println("Differensen ar: ");
    Arrays.sort(nyvektor);
         int counter2 = 0;
                        for(int i = 1; i < nyvektor.length; i++)
                        if(nyvektor[i] == nyvektor[i-1])
                        counter2++;
                             int[] difference = new int[vektor1.length-counter];
                                                 boolean falsk = false;
                                                 int k=0;
                                                 for(int i = 0; i < vektor1.length; i++)
                                                      for(int d=0; d<vektor21.length; d++)
                                                                if(vektor1[i]!=vektor21[d])
                                                                     falsk = true;
                                                                else
                                                                     falsk = false;
                                                                     break;
                                                                if(falsk)
                                                                     difference[k] = vektor1[i];
                                                                     k++;
                                            for(int i=0; i<difference.length; i++)
                                  System.out.print(difference[i] + " ");

    How about this?import java.util.*;
    import java.io.*;
    class DynamicVectors
      public static void main (String[] args)
        BufferedReader console
          = new BufferedReader (new InputStreamReader (System.in));
        String consoleLine = "";
        StringTokenizer tokenizer;
        System.out.print ("Hur m�nga Vektorer ska lagras? ");
        try
          consoleLine = console.readLine();
        catch (IOException ioe)
          System.out.println (ioe);
        tokenizer = new StringTokenizer (consoleLine);
        int antal = Integer.parseInt (tokenizer.nextToken());
        if (antal<2)
          System.out.println("Du beh�ver 2 st vektorer");
        for (int j=0 ; j<antal-1; j++)
          int vektorSize;
          System.out.print("Ange vektor1: ");
          try
            consoleLine = console.readLine();
          catch (IOException ioe)
            System.out.println (ioe);
          // Here's where the fun starts...
          tokenizer = new StringTokenizer (consoleLine);
          vektorSize = tokenizer.countTokens();
          int[] vektor1 = new int [vektorSize];
          for (int i = 0; i < vektor1.length; ++i)
            vektor1 = Integer.parseInt (tokenizer.nextToken());
    // ...and that's all there is to it.
    int langd = vektor1.length;
    System.out.print("Ange vektor2: ");
    try
    consoleLine = console.readLine();
    catch (IOException ioe)
    System.out.println (ioe);
    // Here's where the fun starts...
    tokenizer = new StringTokenizer (consoleLine);
    vektorSize = tokenizer.countTokens();
    int[] vektor21 = new int [vektorSize];
    for (int i = 0; i < vektor21.length; ++i)
    vektor21 [i] = Integer.parseInt (tokenizer.nextToken());
    Arrays.sort (vektor21);

  • Array Element.Disabled

    I have an existing VI where the original programmer has a 2D array of booleans.
    He sets the Array Disabled property to Disabled and Grayed Out.
    He is also setting the Array Element.Disabled property to Disabled and Grayed Out.
    I am not understanding why it is also necessary to do the latter.

    Yeah, my quick test shows there is no point in also setting the disabled property of the control in the array.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Chart array elements separately

    Labview forum,
    I have a for loop which produces an array of 2 elements.
    This is contained within an outer loop.  Inside the outer loop, I have connected the array to a chart function.  For each outer loop iteration, the the chart plots both array elements as sequential elements in the same plot.  This was not the behaviour I wanted.
    Instead, with each outer loop increment, I would like each array element to be added to a separate curve on the same chart axes.  Thus, in this case, two curves would be plotted simultaneously.
    How can I achieve this?
    Attached is a simple example of my current situation.
    Regards,
    Jamie
    Message Edited by Jamieg on 09-17-2007 06:45 AM
    Using Labview version 8.0
    Attachments:
    sample chart loop.vi ‏14 KB
    sample chart loop1.vi ‏14 KB

    An alternative solution uses the "array to cluster" function. (Don't forget to set the cluster size!)
    Message Edited by altenbach on 09-17-2007 07:50 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    sample_chart_loop1MOD.vi ‏15 KB
    multichart.png ‏2 KB

  • Change array element "initialized" property

    I'm a newcomer here. And it is a simple question.
    The aim of this part is to save the array data.
    You can see that if the array element is uninitialized, it won't be saved to spreadsheet, which saves space in the disk. So can I change the "initialized" property of this array element back to unitialized?
    Thanks
    Solved!
    Go to Solution.

    You can "right-click the element...data operations...delete element".
    (This has nothing to do with "uninitialized". The size of the array is indicated by the bright elements, the dull elements are outside the valid range, which has nothing to do with the size of the container. Your first array has two elements and your second array has three elements.)
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Java Hot Spot crashes when trying to start a desktop swing app

    I am trying to start a desktop app and it crashes almost immediately The system is SUSE SLES11, jdk1.6.0_18 64bit Since I can run other java apps (Eclipse being one of them) there must be something specific about this app. Any suggestions? Thanx # A

  • ITunes to version 10.6 updated and now crashing upon launching

    I updated my iTunes to version 10.6 yesterday and now it's crashing everytime I try to launch it within seconds of opening it. An error message pops up and says Windows needs to close the program due to an unexpected error. I've tried repairing the f

  • Camera Import Plugin XDCAM - not working for me!

    I recently discovered Sony's "Camera Import Plug-In for Apple Final Cut Pro X (FCPX)." Sounds really useful, so I went for it. Downloaded it in seconds, installed it (and got the "Installation Successful" confirmation). Launched FCP X - nothing! Usin

  • Budget Check/Overrun

    Hi All, I have maintained the tolerence limit for this budget profile with as transaction group"++" and message type 2. But i get warning message only when i make a posting to the WBS element and not when i make posting on the network corresponding t

  • Costcenter - Change (Trip)

    Hi, We wanted to change the cost center of a trip.  We wanted to change it from RFC, Which RFCs can we use to change the Cost centers, for a particluar trip from the back end. thanks in advance Sera