One Dimentional Array Problem

Write an application that inputs five numbers, each of which is between 10 and 100, in inclusive. As each number is read, display it only if it is not a duplicate of a number already used. Provide for the "worst case," in which all five numbers are different. Use the smallest array to solve this problem. Display the complete set of unique values input after the user inputs each new value.
What I have so far is this only...
int array[] = {32, 18, 64, 18, 35};
System.out.printf("%s%8s\n", "Index", "Value");
     for(int counter = 0; counter < array.length; counter++){
          System.out.println("  " + counter + "       " + array[counter]);
     }Someone please help me with this... it's due tomrow and I have no clue how to check if same number has been entered and return the value of 0 for it.

yeah i know it does
everything works
i just had to switch up 2 values because it was giving me a reversed solution
that array[k] into j, also i just switched all the variables into the common i use a lot.
public class Duplication {
      * Method main
      * @param args
     public void duplicate(){
          int array[] = {32, 18, 64, 18, 64};
          System.out.printf("%s%8s\n", "Index", "Value");
          for (int counter1 = 0; counter1 < array.length; counter1++){
               for (int counter2 = 0; counter2 < array.length; counter2++){
                    if ((array[counter1] == array[counter2]) && (counter2 != counter1)){
                         array[counter2] = 0;
               System.out.printf("%3d%9d\n", counter1, array[counter1]);
     public static void main(String[] args) {
          Duplication dupe = new Duplication();
          dupe.duplicate();
}Once again, thank you so much

Similar Messages

  • Comparing 2 one dimentional array

    I have master list and a child list. Need to check whether the values in the child list exist in the master list. Please provide me a code to do this efficiently

    If your arrays are really nested tables then check out the SUBMULTISET condition or the MULTISET INTERSECT operator.
    Joe Fuda
    SQL Snippets

  • A quick Array Problem

    hey all,
    i'm having a dumb array problem, I cannot figure out what I've done wrong !
    I've set up an empty array of JButtons (because that '4' is actually a variable in my code)
    HERE IS THE CODE
    //===========================
    JButton[] buttons = new JButton[4] ;
    for (int g = 0; g < 4; g++)
    Imag[g].setIcon(imageIcons[g]);     
    buttons[g].setEnabled(true);
    System.out.print (buttons[g] + " " + g + "\n");
    //===========================
    My Error is a null pointer exception. And when I take out the:
    buttons[g].setEnabled(true);
    line, I just get the ouput, and it is:
    null 0
    null 1
    null 2
    null 3
    Ok, I know I'm probably making one dumb little mistake, but I have no idea what it is right now, Please Help !! thanks,
    Kngus

    When you want to use an array, you declare it (which you did), construct it (which you did), and initialize it (which the VM did). When you initialize an array of primitives, the primitives get their default value (0 for signed int types, 0.0 for float types, false for boolean, null-character for char) and so do object references (null).
    You are setting up an array of object references. When the VM initializes it, the elements of the array (i.e. the references to the JButtons) are set to null. That's why you're getting the NullPointerException. You need additional code, something along the lines of this:
    for(int j = 0; j < buttons.length(); j++) {
        buttons[j] = new JButton();
    }Now, your buttons array will contain references to JButtons rather than null.
    AG

  • Multi-dimentional array

    I have an multi dimentional array
    it has 5 columns and 8 rows
    A B C D E
    F G H I J
    K L M N O
    P Q R S T
    U V W X Y
    etc
    if i remove the row beginning [1][0]
    how can I get all the ones passed that row to shuffle up to fill the gap?
    A B C D E
    K L M N O
    P Q R S T
    U V W X Y
    ends up as
    A B C D E
    K L M N O
    P Q R S T
    U V W X Y
    Code would be lovely, I am new to this programming lark and I am not sure i like it :'(

    This is something done best (as previously suggested) with collections. Look into the tutorial and APIs for ArrayList and such. However, if you need to use arrays, here is a program that does (rather poorly I would think...)
    public class MultiArrayTest {
        public static void printData(char[][] data, int numRows, int numCols) {
             for (int r = 0; r < numRows; r++) {
                  for (int c = 0; c < numCols; c++){
                       System.out.print("" + data[r][c] + " ");
                  System.out.println(" ");
              System.out.println(" ");
        public static int deleteRow(char[][] data, int row, int maxRows, int maxCols) {
             for (int r = (row-1); r < (maxRows-1); r++){
                  for (int c = 0; c < maxCols; c++) {
                       data[r][c] = data[r+1][c];
             return maxRows-1;
         public static void main(String[] args) {
              char[][] data = { {'A', 'B', 'C', 'D', 'E'},
                                 {'F', 'G', 'H', 'I', 'J'},
                                 {'K', 'L', 'M', 'N', 'O'},
                                 {'P', 'Q', 'R', 'S', 'T'},
                                 {'U', 'V', 'W', 'X', 'Y'} };
              int maxRows = 5;
              int maxCols = 5;
              printData(data, maxRows, maxCols);
              maxRows = deleteRow(data,3,maxRows,maxCols);
              printData(data, maxRows, maxCols);
    }

  • Transposin​g Array Problem

    I need to get the information from a table which has been populated at an earlier point in the program, and convert it to numbers, and then break it up into its individual elements. Both ways of doing this in my attached vi work, but the one method throws three 0's in between columns, when I resize the 2D array to 1D. Any idea why? Is there an easier way to go about this?
    Thanks, Geoff
    Attachments:
    Array Problem.vi ‏26 KB

    Your original table contains 3 extra row which generate 3 rows of zeroes. Your 2D array actually contains 35 elements. the reshape function truncates to 20 elements. After transposing, you throw away nonzero elements while before rehshaping all zeroes are in the tail giving the false apperance of correct behavior.
    The attached modification gives you a button to fix the table size so it works correctly.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ArrayProblemMOD.vi ‏41 KB

  • Regarding iMessage, when i want to send text to a person in my contacts app, i've been getting a message saying the number has not been registered with iMessage.  How can one fix this problem?

    Regarding iMessage, when i want to send text to a person in my contacts app, i've been getting a message saying the number has not been registered with iMessage.  How can one fix this problem?  It works on the iPhone.

    It takes two to tango, maybe it's your recipient that has weak Internet/Cellular connections.

  • Help needed with HTC One regarding mic problem with noise cancellation

    I picked up an HTC One last week, and so far I am loving the phone.  Great build quality, screen, sound - all as advertised.
    However, there is one very annoying problem I am having.  When I am talking to someone, I can gear them great, but they keep telling me I sound muffled or robotic.  I performed some tests, and the problem appears to be something with the dual microphones and the HTC One's noise cancellation features.
    Here are the tests I ran:
    Typical phone call, with holding the phone as I normally do on the sides and to my ear.  Call result, pretty muffled voice.  I'd give the call quality a 5/10.
    Help the phone as I typically do, but covered the mic hole on the back of the phone.  This definatelyimproved call quality.  Was louder and clearer, but not perfect.  I'd rate it at 8/10.
    Help the phone towards the bottom, using my hand to kind of cup the bottom directing the sound to the bottom mic.  This was a further improvement in sound quality.  Rating would be 9/10.
    Help phone as normal, but covered the bottom mic hole.  Very low volume and muffled sound.  Rating a 4/10.
    Talked directly into the bottom of the phone into the bottom mic.  This gave perfect call quality and volume.  Rating a 10/10!
    Talked directly into the mic on the back of the phone. Horrible quality, couldn't hear hardly anything. Rating 0/10.
    Speaker phone on, held the phone up and moved it around as I would normally use a speaker phone.  Call quality was really nice.  Id give it 9/10.
    Speaker phone on, covered back mic hole and used speaker phone as in #7.  Very bad quality, rating 1/10 for call quality.
    Speaker phone on, covered bottom mic and help speaker phone in hand.  Really good quality, even an improvement over test #7.  Would give the call quality a 9.5/10.
    Speaker phone on, placed face down on table.  Volume a bit low, a little muffled.  Call quality 6/10.
    Speaker phone on, place face up on table.  A bit worse than test #10, low volume and a bit muffled.  Call quality is 5/10.
    Based on these tests, I know this problem has nothing to do with the network CDMA connection.  It is obvious that the noise cancellation features are a bit too aggressive, or I have some hardware problem with one or both mics.
    I question wether its really a hardware mic problem, because on non-speaker phone calls, talking directly into the bottom mic gives great quality.  And on Speaker phone, covering the bottom mic makes the speaker phone sound really good.  That's why I think there's something going on with the "Sense Sound" noise cancellation.
    Is anyone else seeing the same issues?  I want to be able to hold the phone normal on a non speaker phone call and get good quality.
    Looking for any tips and advice anyone can give.  Is it worth exchanging for a new one, as I am still in my 14 day window.
    Thanks in advance for the help!

    Here are some other threads that seem to be having similar issues:
    http://forum.xda-developers.com/showthread.php?t=2262648
    http://forum.xda-developers.com/showthread.php?t=2294532

  • Deleting row of zero in one dim array

    In my application, I am using the first column of the table as a selection from the combo box. The table is converted to one dimension array of 200 rows and 1 column, Some of the rows have zero value which is visible in the combo box selection , I need to remove the rows containig zero before linking to combo pbox can it be possible
    With regards
    anusree

    Hi,
    Please find attached the VI doing what tst has explained
    The For-loop indexes each element from the Input Array, Insert the element into the new array if it is a non-zero.
    If it is a zero, simply shift the array without any insertion.
    Cheers!
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com
    Attachments:
    Remove 0s from array.vi ‏23 KB

  • Has anyone one else had problems redeeming the code for the free onetime download of Star Trek 2009 Movie?

    Has anyone one else had problems redeeming the code for the free onetime download of the Star Trek 2009 Movie?

    dawnfromcabot wrote:
    ITUNES HAS CHARGED MY DEBIT CARD $99.99 FOR GLOBAL WAR RIOT-SOME GAME I DID NOT KNOW WAS LOADED ON MY OTHER PHONE; HOWEVER, WHEN I PULLED UP THIS APP TO SEE EXACTLY WHAT IT WAS WAS I SURPRISED TO SEE I COULD DOWNLOAD IT FOR 'FREE'. I HAVE CONTACTED ITUNES THROUGH THIS REDICULOUSLY CHICKEN SH_T SYSTEM THEY USE SO THEY DO NOT ACTUALLY HAVE TO HEAR HOW UPSET A PERSON IS NOW THAT THEY CANNOT BUY FOOD FOR THEIR CHILDREN BECAUSE OF A MISTAKE MADE ON ITUNES PART.  I DID RECEIVE AN EMAILED RESPONSE FROM STEPHANIE WHO ADVISED THIS WAS PUCHARED ON A PHONE THAT HAS PURCHASED DOWNLOADS IN THE PAST. I WONDER IF SHE THOUGHT TO LOOK AT MY ENTIRE DOWNLOAD HISTORY AND DISCOVER THAT NOTHING HAS EVER BEEN PURCHASED ON MY ITUNE ACCOUNT IN THE AMOUNT REMOTELY CLOSE TO WHAT THEY ARE CHARGING ME NOW.  THAT IS BECAUSE I DO TRY TO MONITOR THIS ACCOUNT AND OBVIOUSLY THIS LAST PURCHASE WAS DONE WITHOUT MY KNOWLEDGE UNTIL I CHECKED MY ONLINE BANKING ACCOUNT, WHICH I DO EVERY DAY.  TO MAKE MATTERS WORSE THE APP STATES IT IS FREE TO INSTALL WHEN YOU PULL IT UP SO NO ONE HAS CLARIFIED TO MY WHERE THE $99.99 COMES INTO PLAY.  I WILL NOT DROP THIS UNTIL MY BACK ACCOUNT HAS BEEN PROPERERLY CREDITED IN THE SAME TIME FRAME IT TOOK YOU TO TAKE MY MONEY. I WILL LAUNCH A COMPLAINT WITH EVERY POSSIBLE ENTITY IN THE ITUNES COMPANY AND BUSINESSES OUTSIDE THAT REGULATE THEIR BUSINESS UNTIL THIS HAS RESOLVED IN MY FAVOR AS I AM THE ONE WHO HAS BEEN VICTIMIZED BY A COMPANY I INVITED INTO MY TELEPHONE NETWORK IN GOOD FAITH!!!!!!!!!!!!
    Reading that is giving me a headache, how about normal type.

  • Spread Sheet Couldn't be Imported, Spread Sheet couldn't be opened because it contains cells outside the boundaries of numbers. Has any one had this problem? It is an excel file that works fine on my mac.

    When I try to import an excell file to numbers on my ipad i get an error message that says it cannot import the file or open the file because it contains cells outside the boundry of numbers. Any one have this problem. it is only one file that i have this problem with and it is an important one. I have no problem working on it with my mac and my excell for mac.

    Number is limited to about 65000 cells so if your Excell spreadsheet is too large Numbers will choke.  This is definitely one of the weaknesses.  If you don't have Excel you can use LibreOffice which is free.

  • Does any one have same problem that can't text on iPhone 4 but can ring ?

    Hi there does any one have same problem just brought iPhone 4
    And I put SIM card in and finally get service but I can ring people
    But can't text as well been told to reboot phone through iTunes
    To make it back to a new iPhone settings been told by Vodafone
    To do it, but will it work?

    RCC0040 wrote:
    Hi,
    Today I tried to send a normal text message to 2 non iPhones today having sent messages successfully to these 2 phones on nye but neither would send.
    So far today I have tried:
    1. Calling, receiving calls and receiving texts from these phones works fine, even today
    2. Checking the send/ receive has my number in both sections. I have also tried a variety of setting combinations here of imessage on off etc
    3. The same with the phone section and my number
    4. Installed latest IOS update
    5. Restored network settings
    6. Turned off and on again
    7. Taken sim card out and cleaned it
    I would be very grateful of any further suggestions because I'm not sure at all why this isn't working today after not having knowingly changed anything since nye.
    Thank you!
    Ask your cell phone provider SMS is a carrier feature.

  • Sort two one dimensional arrays

    I am having trouble sorting two one dimensional arrays. The first array is int type with ID numbers. I use a bubble sort to sort those. The other array is a string array of video titles. When the first int type array of ID numbers sort, I want the second string type array to follow it. I have tried many things and I can not get it to work properly. Here is what I have for now without the string sort. Can someone help me?
    public class Video
         public static void main(String[] args)
         int[] numID = {168, 397, 102, 39, 239};
         String[] videoTitle = {"Godzilla", "Superman", "Hannibal", "Star Wars", "Men In Black"};
         System.out.println("Here are your selections:");
         System.out.println();
    System.out.print(numID[0]);
         System.out.println("\t" +videoTitle[0]);
         System.out.print(numID[1]);
         System.out.println("\t" +videoTitle[1]);
         System.out.print(numID[2]);
         System.out.println("\t" +videoTitle[2]);
         System.out.print(numID[3]);
         System.out.println("\t" +videoTitle[3]);
         System.out.print(numID[4]);
         System.out.println("\t" +videoTitle[4]);
         System.out.println();
    System.out.println();
    //Sorting ID numbers in ascending order
         int a;
         int b;
         int temp;
    for (a = 0; a < (numID.length - 1); ++a)
         for(b = 0; b < (numID.length - 1); ++b)
              if(numID[b] > numID[b + 1])
                             temp = numID;
                             numID[b] = numID[b + 1];
                             numID[b + 1] = temp;
              System.out.println("Here are your selections in ascending order:");
              System.out.println();
         System.out.print(numID[0]);
              System.out.println("\t" +videoTitle[0]);
              System.out.print(numID[1]);
              System.out.println("\t" +videoTitle[1]);
              System.out.print(numID[2]);
              System.out.println("\t" +videoTitle[2]);
              System.out.print(numID[3]);
              System.out.println("\t" +videoTitle[3]);
              System.out.print(numID[4]);
              System.out.println("\t" +videoTitle[4]);
              System.out.println();
         System.out.println();

    There are ways to do that, of which the simplest would be to switch entries in both arrays at the same time. But since Java is an object-oriented language, the better way to do it would be to make a Video object containing a number and a title, put those objects in an array, and sort the objects.

  • Some one is having problems with the timed access in airport last gen?

    I have timed access to the airport, but it seems do not work fine... I have the list of the computer that can have acces to my wifi network , but all people how has the password can go in to my wifi network.
    Any one with this problem to?
    Airport utility 6.3.2
    Airport Extreme 7.7.2 (Last Gen)

    Unfortunately I have the same problem... teaches me not to be one of the first few people to upgrade.  I guess I won't be upgrading to the iphone 5s for a while.
    In any case, last night I requested to update to see the new iRadio feature.  This morning I came back and saw the dumb light blinking. 
    This is too bad... love the products until now, but this feels wrong that now I have to get a mini usb connection just for this.
    C'mon Apple... get the things right!  At least pull the plug on the upgrade, don't get millions of people upset.

  • Hey.. m frm india.. m jus advicing apple dat if dey give apple users to buy apps frm deir balance(money will b deducted..) rather by using visa, credit card n all...! its good if apple does dis.. its one kind of problem in india for apple users! i thnk

    m frm india... m jus advicing apple dat y not dey give apple users to buy apps wid d us of their balance( money will b deducted frm their balance) rather by using visa, credits cards n all..... its one kind of problem in india for apple users..I THINK...!!

    Nobody from Apple reads these forum, this a user forum. 
    Send your suggestion here http://www.apple.com/feedback/

  • Can not get email after updating to 8.1.1! Deleted account and now cannot add as will not verify due to Apple something timeout messages? Any one else having problems?

    Can not get email after updating to 8.1.1! Deleted account and now cannot add as will not verify due to Apple something timeout messages? Any one else having problems?

    Hi tania184,
    Have you contacted your email provider to make sure there are no problems on their end? If they say their email servers are working properly, check the outgoing and incoming mail servers entries on your iPhone to make sure both are entered correctly. Enter the outgoing mail server even if the account setup indicates that is optional.

Maybe you are looking for

  • I can't log into to my icloud because it asks for apple id but then says that apple id is not the same as the icloud id

    I just signed up for icloud.  I previously had itunes on my old computer.When I went to sign up to icloud it told me my password was wrong so I changed it.  When I went to sign into icloud (after installed)  It told me I have to log in using my Apple

  • How do I seperate my iPhone & iPad from my wifes iPhone?

    Ok so I see a lot of answers on here that may help but not sure and Im afraid to try with out getting better info so here goes: My iPhone and my wifes Iphone are both on the same itunes account this worked fine until the IOS5 update. She updated her

  • N70 Screensaver

    I have the horid "disco" as my screensaver which frankly makes me feel sick watching it. I have deleted the picture from my phone but the screensaver is STILL there. I can't even find where to change the screensaver on my pjone. Please help! Sprock A

  • Interactive Reports and APEX 3.0

    hi -- I built some initial prototype pages (forms, reports, etc) in Apex 3.0. Have recently upgraded to 3.2, and in building more reports I see that there is an option for an Interactive Report (and it's the default). Was this available in 3.0? I was

  • There is no "Great Britain" in the German version of icloud.

    Hi, I use the German version of icloud. In the address section there is no chance to choose "Great Britain". I cannot type it either. What went wrong?