compare a variable to all elements in the array

I know that this could be done by declaring unique visitors [10] instead of calling a variable for the length, but I'm learning how to use java more effectively. Here's the complete code:
[code]
package findunique;

/**
*
* @author user
*/
import java.util.Scanner;
to import java.util.Arrays;

public class findUnique {}

/**
@param args command-line arguments
*/
Public Shared Sub main (String [] args) {}
bring the scanner to capture the entrance
The scanner keyboard = new Scanner (System.in);
initialize variables and arrays
int [unique];
int loop;
int loop2;
int rt;
[] int number;
single int;
unique = 1;
Loop =-1;
loop2 =-1;
unique visitors = new int [unique];
number = new int [10];
loop for 10 entries
While (loop < = 8) {}
Add 1 to the loop counter
++ loop;
RT = 1;
Launch iner loop in order to ensure the entry is acceptable parameters
While (rt == 1) {}
System.out.println ("Please enter an integer between 10 and 100 :");
Number [Loop] = Keyboard.nextInt ();
If (number [loop] > 10 & & number [loop] < 100)
RT = 0;
else System.out.println ("Input out of range. Please try again. ») ;
}
Make sure the number is unique
If (number [loop]! = unique visitors [0] & & number [loop]! = unique visitors [1] & & number [loop]! = unique visitors [2])
& & number [loop]! = unique visitors [3] & & number [loop]! = unique visitors [4] & & number [loop]! = unique visitors [5]
& & number [loop]! = unique visitors [6] & & number [loop]! = unique visitors [7] & & number [loop]! unique = [8])
{++ loop2;}
{If (loop2 > unique)}
++ unique ;}
visitors unique [loop2] = number [loop] ;}
}
System.out.println ("unique integers entered are:" + Arrays.toString (unique));
}
}
[/ code]


I get an error IndexArrayOutOfBounds because of this line:

If (number [loop]! = unique visitors [0] & & number [loop]! = unique visitors [1] & & number [loop]! = unique visitors [2])
& & number [loop]! = unique visitors [3] & & number [loop]! = unique visitors [4] & & number [loop]! = unique visitors [5]
& & number [loop]! = unique visitors [6] & & number [loop]! = unique visitors [7] & & number [loop]! unique = [8])

I need to find a way to say:
If (number [loop]! = unique visitors [allElements])

where [allElements] is all the elements of the array in time.
The goal is to keep the size of the visitors array [unique] only the actual number of unique integers entered.

802281 wrote:
using the loop check that the number is unique
for (int i = 0; i)< 10;="">
If (number [loop1]! = unique visitors [i] & number [i]! = 0) {}
If so add a new one at loop2 and assign the number of the index following unique visitors]
++ loop2;
visitors unique [loop2] = number [loop1];
} }

As I mentioned in the post above, here's the problem. See the code above I gave properly.

Tags: Java

Similar Questions

  • Reference element of the array by name

    Hi, I have a table containing the different sprites... I am wanting to make reference to the sprite I want by its name rather than by its index in the table, and I was wondering if theres an easy way to do this? I know I could do a loop through all elements in the array and to see that we have a name that is equal to the name I'm looking for, but is something in the sense of myArray [elementName] possible?

    Well, if you did a loop for, you could then do something like:

    myArray .name = i;

  • Can I programmatically change the default property to create for all elements of the front panel?

    Can I programmatically change the default property to create for all elements of the front panel?

    I need to make the logout button, when click on, takes care of all the default values of my fron Panel.

    There is no way to programmatically call the functionality of an editor 'Use default' or 'Load Default'. To do it yourself, you will need to write your default values for each control explicitly in the diagram, when the user press the logout button.

  • Why all the elements of the array does not appear?

    Hello

    I'm learning about the handling of tables.  The example finder includes this one, 'build array_forum.vi', which shows the two modes, concatenate and adding, I understand, HOWEVER, I can't understand how they built this vi.  For example, I can find the Array function to build, but I do not understand how they created the "digital data table 1" "data table 2" digital... etc, and I can't find the functions on the pallets that cause display "build the CONCATENATE entries table". ".  Where are these blue functions?

    Where these functions are found in the palette, and how we build them like that?

    The other vi indicated here, 'for loop array_forum.vi' is my attempt to reproduce, but it doesn't show all the elements of the array; However, it only displays a SINGLE element, the last element of the array.  How can I view all the items in the table I am creating using the FOR LOOP?  I am doing something wrong with the LOOP FOR?

    Thank you

    Dave

    Right-click your scoreboard, uncheck the "Display as icon" and see what happens.  There are two ways of viewing terminals, most of us like the simple point of view, the default value is the display of the icon.

  • How can I create a button with alpha background and text? When the alpha element group influence all elements, but the text remains 100%

    When the alpha element group influence all elements, but the text remains 100%
    I try with the Group of elements and no group, but include elements in the 'State' of the widget library button. Nothing!

    Explain dough my problem and please excuse my English...
    I need to have a transparent background with text (name and job) at the start. When I rollon with the cursor of the mouse on the button background should take a color with 60% alpha, required text full color stay, but if I group or insert State of the item on Rollo button mouse everything take alpha 60%

    I need to regroup or insert in elements went State button because if they are ungruoped to mouse Rollo on bottom its all is ok, but when the mouse passes over the background of text out you of you initial state.

    Can someone help me please?

    I think I know your problem - are you using the opacity of the 'effects' rather than opacity to "fill" - one of the effects will affect the entire element rather than just the rectangle.

    Use this opacity

    not this one

  • mathematical calculation in script on each element of the array.

    Hi all

    I am trying to write the VB script in which I want to do different mathematical operation on each element of channel-specific data. For example, for each element I want to find the next two index given way and both before and after publication of the results on the basis, then it is more calculating.

    It will be very useful if someone can guide me in the execution of operation on the elements in the array inside the script of tiara, that we can do in labview using indexes in the table. There are built-in math and statistics in tiara tab analysis tool. But I want to design for my custom mathematical operation.

    Thnks

    HS

    Hi HS,

    Here is a version 10.2 tiara from what I understand ask you:

    Window = 2

    Denom = 2 * window + 1

    Threshold = 10

    Chnum = CNo("[1]/Speed")

    FOR i = 1 + ChnLength (Chnum) window - window

    Sum = 0

    FOR j = i - window to i + window

    Sum = sum + ChDX (j, Chnum)

    NEXT ' j

    Ave = sum/Denom

    IF Ave > threshold CAN

    ' do action of contingent

    END IF

    NEXT ' I

    Brad Turpin
    Tiara Product Support Engineer
    National Instruments

  • 'Replace the element of the array' replaces not only indexed items

    Hey masters LabView,.

    Fairly new to Labview and I'm trying to sort out how to create a table of images. I know that the total number of images I want in my 'stamp' (not the buffer of LabView), so I'm the initialization of an array of this size. Can I bring this table in a loop For with a shift register, and I want to capture images and write them in the table of the buffe continuously (a comment: I do a circular buffer, but I don't want to implement in LabView, because there a lot of things that I don't need and I will eventually have to the process to be as thin as possible).

    Here's the problem (I assume an implementation, that does not decompose LabView):

    I expect:

    AN element of the array, in the position indicated by the index of the loop [i], is replaced by the image newly caught

    I get:

    All THE elements of the array becomes the image newly caught.

    (I can tell because I taste under the table, grabbing a single image from a constant "Check Array" index - may 7, for example.) But my index of the loop [i] value is 13, and the subsample becomes again the image newly caught.

    What a ridiculous thing I am doing wrong?

    Any help would be greatly appreciated.

    Ah, I just noticed something.  Initialize you an array of references at the beginning of your program, but it is a complete picture OF THE SAME REFERENCE: you must call the IMAQ Create in a loop so that you actually get unique references in your table.  You must have a different NAME for each image.

  • Type a table defined clusters to hold configuration data - definition of default values for each element of the array

    Hello

    I was wondering if I could get some information and opinions on the use of an array of type defined clusters to store configuration data.  I am creating a program to test several EHR and wanted to have a control of type defined for each HAD with the information needed to create the DAQmx tasks for all signals for it must HAVE.  I am eager to do so that the data are encoded in hard and not in a file that the user might spoil.

    Controls of type def are then put into a Subvi who chooses as appropriate, one based on the enumeration of Type DUT connected to a case structure.

    I have problems with the control of the defined type.  I see issues when you try to save a configuration unique to each element of the array in the array of clusters.  Somehow, it worked at first, but now by clicking on "Operations on the data--> default font of the current value ' on individual elements of the cluster or the entire cluster (array element) does not save data when I re - open the command def.  What I am doing wrong?  I'm trying to do something with the berries of the clusters that I shouldn't do?

    I enclose one of the defined reference type controls.  I tried to change it bare to see if that helped, but no luck.

    To reproduce, change the resource string for the element 0 of the array and do the new value by default.  Then close the def of type, and then reopen it.  The old value is always present in this element.  The VI is saved in LabVIEW 2012.

    The values of a typedef are not proprigated to the instances of the control. They get if created WHEN data values have changed. They will be not updated with the changes to come. You must create a VI specifically to hardcode your values or to implement a file based initialization. The base file would be much better and more flexible. If you don't want users to change the data simply encryption. There is a wedding blowfish library that you can download.

  • Changing the properties of the individual elements in the array

    In the attached VI, I have a table 1 d of the slider ('Phase Coefficients') controls where each element of the array represents the coefficient in a polynomial of arbitrary order. The problem I have is that the range of slider, I put to the coefficient of the lowest order (element 0 of the array) becomes quickly impossible for one more order coefficients (> 5 elements). Small changes in the highest order coefficients dramtically change the global polynomial.  I want each element/slider to have its own line, but I know that's not strictly possible that each element of a table shares the same properties. I've implemented a work around (use boolean to activate) in which the range of all cursors is set according to which the item is viewed, but my implementation prevents the modification of the range during execution of the VI. Is it possible to adapt my method (or use another method all together) in order to allow different, editable for each slider element ranges?

    Thank you!

    Each element of an array must have the same properties.  They can only differ in value.

    You can have an array of clusters, and each group can have the slider control.  Here, you will be able to regroup a slider with different properties in the cluster build clusters in a table.

  • Drag and drop the element of the array of Clusters

    I have a project that includes an array of 'tests', each of which is a cluster that contains an array of 'numbers', a matching the regular expression string and an array of "tasks" (all of them, is in turn, a group of elements).

    It is:

    • Tests (table of):
      • Cluster:
        • Reference numbers (an array of strings)
        • Regex (string)
        • Tasks (table of):
          • Cluster:
            • Task type
            • Basic channel,
            • Measuring channel
            • Other channels

    I wish I could drag and drop to rearrange the task table in an individual event.  (It is a nice-to-have rather than a urgent request - more for my own learning that no matter what).  For now, I've implemented "Move up" and "Move down" buttons

    Examples are fine for a single cluster that includes a table or an array of objects.  As soon as we have an array of clusters, it is difficult to access individual items within a specific cluster.

    Who that it be completed can drag and drop into such a facility?

    Curiously,.

    Geoff

    Hello GeoffF,

    It's certainly doable and you can even use the standard start drag and drop methods/events, the trickiest part is to determine the table of the elements that are selected on the mouse towards the top/mouse downwards and the swap of manual handling.  Fortunately, there are a few decent examples of how do this out there already, I suggest you take a look at this one:

    Example of community: determine the Index of the clicked element Array in LabVIEW

    https://decibel.NI.com/content/docs/doc-22434

    That should give you the selected table indexes, and then all you have to do is to move the elements around around the drop event.  I have attached a very basic demonstrative example that uses this code I just linked (you need to download that as well) and the events referred to swap two elements of the array.   The attached code is just thrown together, you'll want to design something more robust and scalable to any sort of actual use.

    Kind regards

  • Could not save the different string value to each element of the array

    I have a configuration of VI to read several channels Veristand project.  The entrance is a table 1 d of channels, (an element for each channel, I want to read).  The channels have different names, each of the elements in the chain must be different.  I am able to edit each item and run the VI, and it works fine.  However, if I save, close and reopen the VI, all elements show the same value (what happens to the value of the last element for which I defined a default value).  Is this behavior planned, or have I missed a configuration setting which would allow different string values?  Please notify.  Thank you.

    GSinMN

    Make sure that you select the table and not only one item when you right click-> set by default on the front panel.

  • Automatic indexing does not as soon as the first element of the array.

    Hello

    I have a state machine that uses automatic indexing in most of his State to write the registry to set the part for some test.  When the state machine reaches the section 'Now playing' (the fourth State, second battery sequence) I have a picture of two equal elements related to looping for to write the required registers for this specific test.  When I enter the current state read the the first address is the second element of the array which is '1' location and not the first address that must be '0 '.  I closed the program and restarted LabVIEW but I always get the second element in this loop that maintain the form part works correctly and I get an error because the first element turns on the chip.  Is there something I'm not see when it comes to self that he would keep from starting at the first element of indexing?  Please take a look and let me know what I can do wrong.  I have attached the main program and the print loop results screens and test probe.  Any help will be great.  It worked last week.

    I don't see no problem at all when I copy the loop in an another VI in order to run it. Your jpg shows nothing on the values of the probe.

  • Coordinates of the elements in the array

    Hello
    I'm playing with mouse click coordinates, especially because his Friday afternoon , but also because it might be useful

    In the attached code, I want to click on one of the channels of my table control and what element of the array corresponds to (which later will be used to draw the other pieces of the code based on the content of table)

    I can use the position of the table and the coordinates of the mouse and everything works fine.
    BUT... only if I select the zero element until I run the code. If I select another element, then run the code, I get wrong results.

    -Are there a way to get the coordinates of the element zero of my table regardless of what the user has done?

    I can think of workarounds using the coordinates of the control table (rather than details of the chain), but it is affected by the label size/visibility control feels so less reliable.

    Using version 8.5.

    Thank you
    Ian

    There is a utility VI of the repository of LAVA located here.

    Dealing with this problem:

    Tone

  • Last element of the array

    Hello

    Running mod, when I add elements in the table, I want to see in the last element of the array automatically.

    How can I do that. (without using the vertical scroll bar).

    In a thousand words or less.  Nodes property allows you to programmatically access the properties of the objects.

    (Yes, you will need to run twice to see the result I have no default value)

  • Change of FG and background color of the individual elements in the array

    Is it possible to change the color of foreground and background of the individual elements of the array?

    According to the the link below it is not.  But that was 4 years ago and I wonder if it's possible with the new version of Labview.

    http://forums.NI.com/NI/board/message?board.ID=170&message.ID=125484&query.ID=927250#M125484

    I could not find a way to do it using Labview 8.2.1.

    Thank you

    Adam

    No, you can't.  The tables have to share almost everything except the real value of the data.  As mentioned, you can use a second indicator to indicate your values of interest.  If you just want to change the background color, you can make a table of squares of color which lies behind the numbers array.  Make the background of the numbers (and the transparent table container.  You can do it 'look' as the BG of the numbers is changing.  The FG Color is not as easy.

    A (maybe better) alternative is to use a table or a listbox control to display your table.  They allow you to change the colors of the cells.  You will need to convert your table to an array of strings.  If your table is small, the hit on the treatment will be not significant.  But if you have REALLY large picture, you'll notice put worn times on day of the table/list box.

Maybe you are looking for

  • Aurora Firefox crashes when opening multiple tabs

    Hi all So I use firefox aurora for some time without running into any problems, but since this morning, aurora crash whenver I open 2 + or there are several tabs that use the flash player plugin (for example Facebook and Youtube is a combo that alway

  • HP officejet pro 8600 has made an update and now it takes forever to print a page.

    Windows xp sp3.  There are sometimes as long as it cancels out just.   The update request has shown on the printer, I pushed Yes.  No updates on pc.  Any idea on how to get to his car fast?

  • G550 OSD Hotkey problem

    Hi every1 I have a Lenovo g550 (20023 model name) and after installing the vista hp sp2, I can't do the osd shortcut key works. I tried to install 7jif12ww.exe (I installed, not only it extracted) after installation restart request, after the reboot,

  • Cursor moves on its own

    Periodically, my cursor moves on its own and has been a problem for a few weeks now. Initially, he started with the built-in cursor not only movement erratic but also stuck in place on the right side to her screen/only up and down. To try to solve th

  • Impossible to upgrade my German version from Windows 7 Pro to Windows 7 Ultimate

    I have the German version of Windows 7 Pro that I bought, I would like to be able to display in English.   I understand well there is no LIP and I'll need to upgrade to windows 7 but cannot do my upgrade Express Manager...  He tells me that it is not