Comparing array members

i cant solve the 2nd part of this prob (found in this forum):
// Generate lottery numbers (from 1-49)
// Print number of occurrences of each number
public class Lotaria {
     public static void main(String[] args) {
          int x = 1;
          int p = 1;
          int s = 1;
          int n = 1;
          int[] loto = new int[49];    // n?s do loto
          // Generating lottery numbers (from 1-49)
          for ( n = 0; n < 49; n++ ) {
               loto[n] = (int)(Math.random() * 49 + 1);
               System.out.println(loto[n]);
          for ( p = 0; p < loto.length; p++ ) {
               for ( s = 0; s < loto.length; s++ ) {
                    if ( loto[p] == loto[s] ) {
                         x++;
                         System.out.println(loto[p]
                                          + " ocorre " + x + " vezes");// prints nonsenses
}looks like (inside the if) i'm comparing every array element to all the others and then counting each repetition...
can someone sort me out of this, or at least give me an hint? (pls dont ask for interfaces)

I did it!
// Generate lottery numbers (from 1-49)
// Print number of occurrences of each number
public class Lotaria {
     public static void main(String[] args) {
          int x = 0;
          int p = 1;
          int s = 1;
          int n = 1;
          int[] loto = new int[49];
          // Generating lottery numbers (from 1-49)
          for ( n = 0; n < 49; n++ ) {
               loto[n] = (int)(Math.random() * 49 + 1);
               System.out.println(loto[n]);
          for ( p = 0; p < loto.length; p++ ) {
               for ( s = 0; s < loto.length; s++ ) {
                    if ( loto[p] == loto[s] ) {
                    x++;
          System.out.println(loto[p] + " ocorre " + x + " vezes");
          x = 0;
}i think the 3rd loop (my original idea) can be more elegant but right now i cant cope with it
the secret was in resetting "x"!...
thanks to both for helping me

Similar Messages

  • Compare two members from the same dimension in HFR

    Hi,
    Is it possibe to compare two members from the same dimension in HFR? The requirement is to compare Year and Week members from the same dimension. The Week date will be selected from POV. The corresponding Year date should be displayed in the report. Week dates are in the format W2008-03-07 and Year dates are in YTD2008-03-07.
    The dates are same except the preceding character.I am unable to compare these two. In my understanding there's no substring or replace functions in HFR.
    Kindly help. Thanks in advance.
    Regards,
    Uma

    Hi,
    How is your database structured? it may be possible to use the 'RelativeMember' function if it will always be the same number of steps between the 'W' member and the 'YTD' member, e.g. if your hierarchy is something like:
    Time
    .Weeks
    ..W2008-03-07
    ..W2008-03-10 etc.. for 52 weeks
    .YTD
    ..YTD2008-03-07
    ..YTD2008-03-10 etc.. for 52 weeks
    In your report select 'Current Point of View for Time' in one row/column and in the other use:
    RelativeMember set up as follows:
    Member: Current Point of View for Time
    Offset: 52
    Hierarchy: Time
    RelativeMemberList: Lev0, Time
    UseFirstDescendant: leave unselected
    Hope this helps
    StuartGame
    www.analitica.co.uk

  • Script to compare membership ( members + member of ) for groups in 2 domains

    There are 2 separate domains with same group names that were migrated.
    Is there a way / script in place to compare the members and member of attributes for a list of such groups ?

    You can use Powershell to do this comparison but this would require some development.
    Compare-Object cmdlet can help here: https://technet.microsoft.com/en-us/library/ee156812.aspx?f=255&MSPPError=-2147217396
    More if you ask them in Powershell forum: https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverpowershell&filter=alltypes&sort=lastpostdesc
    This posting is provided AS IS with no warranties or guarantees , and confers no rights.
    Ahmed MALEK
    My Website Link
    My Linkedin Profile
    My MVP Profile

  • Comparing arrays - help!

    Hello. I've been trying to solve this problem for hours, and I would be most grateful for any help you can give me.
    Basically, I'm trying to compare two arrays of char and tell first how many are the same in the same place (I can do that) and then how many are the same but not in place. However, if there are two of one char in one array, and one of the same char in the other, I only want to count it once.
    The problem is, I can't figure out how to do this. I'm using for loops and then setting the char to 0 if it finds a match. This doesn't work. I tried using a series of if statements but I got weird run time acceptions sometimes, and when I put in more if statements to combat that, 1.) it got too confusing and 2.) still only worked half the time. So I'm back to the for loops.
    Here's what I have:
    for (int j = 0; j<guess1.length; j++){
    for(int k = 0; k<code1.length; k++){
    if(code1[k]== guess1[j]){
    code1[k]=0;
    guess1[j] = 0;
    almost = almost + 1;
    So if the code is BBYG and the guess is BWWY, it should return 1 correct and one almost. It will return the one correct, but then return 3 for the almost. It looks at the B in guess which already returned the correct and find it an almost against both B's. When it should have been set to 0 in the correct for loop.
    Sorry, I ramble a bit. Hope you can help!
    Thanks.

    You're gonna love this.
    Unless you have some annoying and patently backward lecturer who wants you to everything the hard way then get ye nose into:
    1. the Collections framework.
    http://java.sun.com/docs/books/tutorial/collections/index.html
    2. and the Collections class itself.
    http://java.sun.com/javase/6/docs/api/java/util/Collections.html
    Hint: a Map can be used to find the distinct items in a list.

  • Compare arrays

    Hello all, I am new to labview and i am trying to compare two arrays to see if they are equal. What i am trying to do is read cell values from excel and move them into an array. Then i would like to compare that array with a constant array in my labview program. Any help is greatly appreciated.

    Do attention with the "aggregates" function.
    Comparing two arrays, for example 3,2,1,0 and 3,2,1 gives "different"
    When comparing if all values in an array are zero, the dimension must also be right !
    So before comparing the values, I compare the length, causing an error if unequeal.
    In my case, compare if everything is zero, I use the "Array max&min" function. (Max<>0 and Min <>0)
    Message Edited by ST5 on 08-11-2009 05:00 AM

  • How to compare array of String with column of a table

    Hi,
    i have a array of string(say array is of length 1000). I want to
    compare those string in array with one table column
            - whether that table column has a string
                            if yes
                                            do nothing.
                            if no
                                            then insert that string into table.
            - whether table has obsolete row i.e, the one present in table and
    not in array
                            then delete that row.
    How do i go about this, because i see, it is not feasible to loop
    through array and search table to find new string OR loop through each
    row from table to find some obsolete row
    How can i accomplish this task more feasibly(without running query for
    each string, for comparission)? Is there any way to find this kind of
    problem. I would have been easy if i had to compare two tables(with
    UNION and INTERSECT), but it is not the case.
    thanks,
    kath.

    I'm not sure, whether I understand your problem correctly. Only two comments:
    - if both arrays are sorted, all can be done running exactly once simultaneously through both arrays.
    - if the column is marked as UNIQUE, all column strings will be different. I.e. you cannot insert the same string a second time.
    Regards  Thomas

  • Comparing array elements for equality

    Hi
    I have written a simple program that works as a lottery number predictor. It works fine except for the fact that sometimes 2 numbers will be the same. Does anyone know of a method that compares an array element to the others to test for equality?

    ok I've had a go at implementing a solution. I worked it out on paper so I haven't tested it yet in the program. Let me know if you can see any errors that I can't.
       boolean numNotSame = true;
       int[] lottery = new int[5];
       int currentNumber;
       start:  //label to return to if 2 numbers are the same
       while(numNotSame){
          for( int j = 0; j < lottery.length; j++){
              currentNumber = 1 + randomNumbers.nextInt(34);   //get random number
              for( int i = 0; i < lottery.length; i++){
                 if( currentNumber == lottery)
    continue start; //if numbers are the same begin again
    } //end inner for
    lottery[ j ] = currentNumber; //set array element if number not used yet
    } //end outer for loop
    numNotSame = false; //set false so while loop will end
    } //end while block

  • Maximum users, array members and applications

    Is there a limit for the following:
    Maximum concurrent users connected to an SSGD array?
    Maximum person objects in ENS?
    Maximum configured applications in ENS?
    Maximum applications linked to a profile?
    Maximum applications shown on the webtop?
    Maximum members of an SSGD Array (1 primary and x secondairies)?
    Thanks,
    Remold | Everett

    Is there a limit for the following:
    Maximum concurrent users connected to an SSGD array?no hard limit, max concurrent users is based on resources, RAM, CPU, networking.
    Maximum person objects in ENS?no hard limit again, with the use of Directory Servers, there is really no need to create person objects anymore. We have seen upto 3000 person objects in ENS before. No major problem seen.
    Maximum configured applications in ENS?no hard limit.
    Maximum applications linked to a profile?no hard limit, we've seen 100s of links in a profile before.
    Maximum applications shown on the webtop?no hard limit, but the more objects you have in webtop the more JVM Heap that will be consumed.
    Maximum members of an SSGD Array (1 primary and x
    secondairies)?rule of thumb is to try to keep it to 10 or less in an array. 1 primary (dedicated, no webtops or emulator sessions hosted off primary) and 9 secondary servers.
    You are alway better off using fewer larger capacity servers than many smaller capacity servers.
    >
    Thanks,
    Remold | Everett

  • Comparable array

    Hi,
    point of intrest as was looking in a book and one of the excercises was to make a generic storage array
    if I have the following
    private Comparable[]  list; and want to add and sort generic objects to this is there anyway I can use either Collections.sort or Arrays.sort, without implementing comparable (I know how to do it this way fine ie having two objects over riding compareTo)
    Am I missing a trick?
    Thanks in advance
    .

    You can use Collections.sort and Arrays.sort with a
    Comparator. Then you don't have to implement
    Comparable.Good point. But it'd be tough to write a Comparator for a "generic" object. If you wanted to compare hash codes or string values it'd be okay, I guess...

  • Compare Array

    I need to compare 2 array tokens to see if they are the same or not.
                if //insert missing code here
                    // Destination identical to origin.
                    error = true;
                    System.err.println("Destination identical to origin. - " + line);
                }The two array tokens are tokens[2] and tokens[3]
    Do you need to use something like "compareTo" or something?? I tried using "if (tokens[2] == tokens[3])" but it still won't work.
    HALP!!!

    It is explained at the method description at the java.lang.String API: http://java.sun.com/javase/6/docs/api/java/lang/String.html

  • Compare Array in Conbination

    How to compare two arrays and find same combinations?

    The correct function to use in column E to solve this problem is dependent on the data that will be in columns F-H. I assumed those columns would contain numbers between 0 and 999999
    Formula in E2 =IF(ISERROR(MATCH(A$2,F2:H2,0)+MATCH(B$2,F2:H2,0)+MATCH(C$2,F2:H2,0)),0,999999)
    Formula in D2 =COUNTIF(E,999999)
    Fill color for A2 through D2 was hand selected, not conditional.
    Conditional format for F2-H2 is "if less than E2 then green fill". Similar conditional format for the remaining rows. If you set this up before putting in the numbers, you can fill the format to the other rows. If you do it later, you can Copy Style/Paste Style to the other rows then change E2 to E3, E4, etc. as you go.

  • Array members cannot connect to Arrayport

    Hy friends,
    four SGDEE 3.42 on Redhat 3 ES worked for month. Today two of them lost the
    binding of the array port (netstat -ln | grep 5427).
    Did some one know, what can cause this?
    regards
    TAB
    Tool Box Solution GmbH
    Gesch�ftsf�hrer Tillmann A. Basien
    Balinger Stra�e 37A
    D-70567 Stuttgart
    Fon: +49 (0) 711 71 68 631
    Hy : +49 (0) 173 87 38 987
    Fax: +49 (0) 711 45 70 899
    ** Mitglied der "Tarantella Brotherhood" **
    mailto:[email protected] / http://www.tbsol.de HRB: 23711
    PGP Fingerprint = 96AF C30C EC14 D930 3019 1CFA F6C4 6E8D 88DB C009
    Publickey: http://www.pca.dfn.de/dfnpca/pgpkserv/ - KeyID: [email protected]

    Hi Magamaruva
    Were you able to use Internet on your Nokia Asha 200 before? Do you already have the correct APN settings from your  network provider? If not please contact them and ask for the correct APN settings for your phone.
    If my post helped you, please don't forget to click on the "White Star" and if it resolved your issue click on "Accept as Solution"

  • Compare array of picture

    Hi all,
    I need some help on these.
    A black and white picture (bmp file) is to be opened and let say that the picture is divided into 4 quarters. If as long as there is a white spot on the top left quarter, the program has to be able to identify it as pattern A.   Likewise if there is a white spot on the top right quarter, the program will identify it as pattern B.
    Please advise and thank you in advance.
    Regards,
    Lip Seng

    Hi,
    It's hard so give a solution without seeing the picture. "Black and white" and "white spots" are open for interpretation. (B&W could be gray, white spots can be different sizes, what is the level of the background noise, how consistent are the picture colors, etc.)
    In the simples case (the spots have high intensity level and are of significant size, background have low intensity level, low bg noise level) I'd try this.
    First, I'd divide the 2d picture data into 4 separate arrays. Then, get a histogram of each array. Get the amplitude of a representative value, and check it against a value. If it is higher, there must be a white spot.
    (Even simpler.. If there is only one pixel against a totally black bg, just use a array max & min, and you instantly have the index of the spot!)
    Regards,
    Wiebe.
    "Lip Seng" <[email protected]> wrote in message news:[email protected]..
    Hi all,
    &nbsp;
    I need some help on these.
    &nbsp;
    A&nbsp;black and white picture (bmp file) is to be opened and let say that the picture is divided into 4 quarters. If as long as there is a white&nbsp;spot on the top left quarter, the&nbsp;program&nbsp;has to be able to identify it as pattern A.&nbsp;&nbsp; Likewise if there is a white&nbsp;spot&nbsp;on the top right quarter, the program will identify it as pattern B.
    &nbsp;
    Please advise and thank you in advance.
    &nbsp;
    &nbsp;
    Regards,
    Lip Seng

  • Comparing Array

    Hello,
    can you plz help me.
    i am checking two array.
    var temItemNo_array:Array = Array(12,13,17,19,20);
    var Item_array:Array = Array(12, 13, 14, 15, 16, 17);
    when checked [B]temItemNo[/B] &&  [B]Item_array[/B] in this arrays 12,13 are same no.
    but when 12 & 13 got continuous common no. that time want stop on 13 no and add on 13+1=14
    Thanks
    JaxNa

    if there are 2 common elements that are adjacent integers then i want next integer
    if 12 & 13 are 2 common element that are adjacent then i want next integer is 14.
    one more example
    if 17& 18 then i want  next integer is 19.
    Thanks a lot kglad

  • How to compare the same array?

    Hello,
    The question not how to compare arrays.
    I have a method that gives results of an array type int.
    for(......){
    int [] arrayFunc(int [] input)
    return arrayOut;
    }I want to compare those arrayOut arrays. I need to find a way to save the first output and then compare it with the newest output. Where do I have to put the temp array to temporary save the array? What should happen if I want to keep track of the results and get comparisons of first, second, third output?
    Thanks

    Still not 100% sure but I try and help. What you need to do is have two references. After you have generated a result compare it to the last result. After the comparison you need to assign the current result to the last result and then go around the loop again to generate a new current result. Below is some code that uses plain ints but I hope it illustrates what I am trying to explain.
    import java.util.Scanner;
    class ComparingNumbers {
      public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int current;
        System.out.print("Number: ");
        int last = scanner.nextInt();
        scanner.nextLine();
        for(int index = 0; index < 10; index++) {
          System.out.print("Number: ");
          current = scanner.nextInt();
          scanner.nextLine();
          System.out.println("Difference is " + Math.abs(current - last));
          last = current;
    }

Maybe you are looking for

  • Why is playerglobal.swc not included in trunk build of Flex 4.5

    Hi, i've downloaded the latest from the Flex SVN trunk, and built it with Ant in every way I can possibly think of (after running Ant -projecthelp).  I have Flex 4.5 configured as my Flex SDK in Flex Builder 3, but since playerglobal.swc is not there

  • Can condition type of down payment in PO create an automatic dwn pyt reqst?

    I have a requirement in SAP that the procurement team raises a Purchase order.  Once the order is approved (out of the release stratergy) the down payment request should be created automatically.  Currently, this is a manual process where in the info

  • How to merge adjustment layers to several layers and export layers to files

    Hi! I have now exactly the same problem as below with over 1000 images, I have saved them in .psd that has over 100 layers each. On top of those there is curves and levels layer that affects every layer below. I want to save all images to .jpg for vi

  • No of inputs differing

    Hi I'm getting the table names as input and i have to do some DML operation based on the table names, the DML operation is, i have to do a delete in that table and i have to do one insert in another auditing table. there are 40 tables, but sometimes

  • MS Word documents in forms/oracle database

    How does one store a word document in the database. Should be able to store the binary file and be able to retrieve it by launching MS word. Can we use BLOB. If so how to store a file into a BLOB column and how to retrieve that when required in forms