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);

Similar Messages

  • I UPGRADED TO WIN 8, CAN'T FIND MY ELEMENTS 8 DISC OR REGISTRATION NUMBER. CAN YOU HELP PLEASE?

    UPGRADED TO WIN8, CANT FIND ELEMENTS 8 DISC OR REGISTRATION NUMBER. CAN YOU HELP PLEASE?

    if you follow all 7 steps you can dl a trial here:  http://prodesigntools.com/direct-download-links-for-lightroom-3-and-photoshop-elements-8.h tml
    and activate with your serial.
    if you have a problem dl'g, you didn't follow all 7 steps.

  • Java 2D array program help please?

    Hi - I'm teaching computer science to myself (java, using jGRASP) using some websites online, and one of the activities I have to do is to make an "image smoother" program.
    I just started learning about 2D array, and I think I get what it is (based on what I know of 1D arrays), but I have no clue how to do this activity.
    This is what the description says:
    "A grey-level image is sometimes stores as a list of int values. The values represent the intensity of light as discrete positions in the image.
    An image may be smoothed by replacing each element with the average of the element's neighboring elements.
    Say that the original values are in the 2D array "image". Compute the smoothed array by doing this: each value 'smooth[r][c]' is the average of nine values:
    image [r-1][c-1], image [r-1][c ], image [r-1][c+1],
    image [r ][c-1], image [r ][c ], image [r ][c+1],
    image [r+1][c-1], image [r+1][c ], image [r+1][c+1].
    Assume that the image is recangular, that is, all rows have the same number of locations. Use the interger arithmetic for this so that the values in 'smooth' are integers".
    and this is what the website gives me along with the description above:
    import java.io.*;
    class Smooth
    public static void main (String [] args) throws IOException
    int [][] image = {{0,0,0,0,0,0,0,0,0,0,0,0,},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,5,5,5,5,5,5,5,5,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0}};
    //assume a rectangular image
    int[][] smooth = new int [image.length][image[0].length];
    //compute the smoothed value for
    //non-edge locations in the image
    for (int row=1; row<image.length-1; row++)
    for (int col=1; col<image[row].length-1; col++)
    smooth[row][col] = sum/9;
    //write out the input
    //write out the result
    "The edges of the image are a problem because only some of the nine values that go into the average exist. There are various ways to deal with this problem:
    1. Easy (shown above): Leave all the edge locations in the smoothed image to zero. Only inside locations get an averaged value from the image.
    2. Harder: Copy values at edge locations directly to the smoothed image without change.
    3. Hard: For each location in the image, average together only those of the nine values that exist. This calls for some fairy tricky if statements, or a tricky set of for statements inside the outer two.
    Here is a sample run of the hard solution:
    c:\>java ImageSmooth
    input:
    0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 5 5 5 5 5 5 5 5 0 0
    0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0
    output:
    0 0 0 0 0 0 0 0 0 0 0 0
    0 0 1 1 1 1 1 1 1 1 0 0
    0 1 2 3 3 3 3 3 3 2 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 3 5 5 5 5 5 5 3 1 0
    0 1 2 3 3 3 3 3 3 2 1 0
    0 0 1 1 1 1 1 1 1 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 0
    c:\>"
    OKAY that was very long, but I'm a beginner to java, especially to 2D arrays. If anyone could help me with this step-by-step, I would greatly appreciate it! Thank you very much in advance!

    larissa. wrote:
    I did try, but I have no clue where to start from. That's why I asked if someone could help me with this step by step...regardless, our track record for helping folks who state they are "completely lost" or "don't have a clue" is poor to dismal as there is only so much a forum can do in this situation. We can't put knowledge in your head; only you can do that. Often the best we can do is to point you to the most basic tutorials online and suggest that you start reading.
    That being said, perhaps we can help you if you have some basic knowledge here, enough to understand what we are suggesting, and perseverance. The first thing you need to do is to try to create this on your own as best you can, then come back with your code and with specific questions (not the "I'm completely lost" kind) that are answerable in the limited format of a Java forum. By posting your code, we can have a better idea of just where you're making bad assumptions or what Java subjects you need to read up on in the tutorials.

  • I can't get my serial number... Help please?

    I purchased the student edition of Premiere Elements 10, and when i was filling out the information to receive my serial number it said that it was successful, but I realized I entered an incorrect email address, and don't have access to the one I entered. How can I get my serial number for the product I purchased?? Is there a way to change the email address it is sent to? Please help! thank you!

    You will need to contact Adobe. (Click Contact Adobe at the bottom of any page on this web site.)

  • Installing Photoshop CS5 on new Win8.1 - serial number not accepted. Help please!

    Hello everybody,
    I just wanted to install Photoshop CS5 on my Windows 8.1 64bit machine, which also happenes to be a new machine. The serial number provided in my Adobe account is not accepted by the installer! The information I could gather from the "support" area points me to a problem which is caused by not properly uninstalling the previous install, am I right? I did not know this. Also, I am no native speaker and feel a little lost on this.
    Please help, I need to use my copy of PS CS5, thanks!

    clean and reinstall per Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6

  • Cannot view RAW pics or update Elements, help please!

    Hi, I have a new Panasonic Lumix FZ28 and I just bought and installed Adobe Photoshop Elements 6 for Mac.  I just returned from vacation where I used my new camera, but when I tried to view my pics, only my jpeg files show up.  So, I tried to update Elements which installed normally, but it will not update.  It says, "The updater is unable to locate the product to be updated"!  What??  It's trying to update the RAW 4.6 update.  I don't know what to do.
    iPhoto won't upload my RAW pics either.  It shows them on the screen, but won't import them.  I also tried copying the memory card to my external hard drive, which it did, but it also doesn't show my RAW pics.  Why is this so difficult!
    Any help would be greatly appreciated!  This is all new to me.
    Thanks!

    Perhaps true, but no other application I know of will completely manage an accurate transfer of data from one computer to another.  Indeed, given the complexity inherent in data transfer a 100% transfer in every respect may well have success odds greater than that of Powerball which, I'm told, would give the ticket purchaser a much better chance of  getting struck by lightning twice before receiving a winning number.
    In any case, I have learned from participation in other forums that too much information is usually more damaging in the quest for the "magic" logic process that delivers solution.  Hence my restriction to information I felt was not only application specific, but relevant. 
    I thank you in no small amount.  There was no way I could have figured out Adobe was leading me on a wild goose chase for the holy grail.  Not their fault.  A big company with lots of products can't help but miss a few links here and there.   Your attention to forum posts and willingness to help has been extremely informative and hugely appreciated.   I hope this discussion thread will be of value to others.
    Thank you.

  • 2 week wait for serial number to CS6 (education) help please?

    Hi, I need help with this! I really dont know what to do next!    i bought a copy of CS6 (education) over two weeks ago, when it (disc) arrived next day I logged in, created an account and emailed off relevant proofs and numbers. Nothing, three days later i phoned Adobe (UK) and (eventually) spoke to somebody who passed me on to the 'activation team', I was on hold for half an hour until I gave up. Next day i waited till 9am on the dot and tried again, was put on to activation team quite fast and spoke to a chap who opened up a 'case', and asked me to send all the documentation again, which i did. The next day I got an email saying that only one of the documents had arrived, strange thought i, however i sent them again. I could see that all the documentation was then there in the'open cases' section, so I waited, and waited...... it has now been two over two weeks since i bought CS6, I phoned Adobe again this morning, spoke to customer serviced who were very helpful, but still had to pass me on.......i waited for 42 minutes then hung up.
    I really dont know what to do next, I even tried Adobe in the States, they said they could not help (I am based in the UK) I have been waiting so long that my course has actually finished!! Any suggestions anyone???? 

    Hi porkerholic,
    I apologise for the delay in providing the serial number.
    I am getting the concerned team involved to expedite the process.
    Do you have any Case number for reference?

  • Getting Input - INT Variable for number or array element? Arggh.

    This is what I have. It is not working. Any ideas?
    package ArrayPackage;
    * @author  Terry
    import java.io.*;
    public class NumArray {
        int num1=1;
        int num2=0;
        int elements=0;
        int[] numArray = new int[elements];
        void insertNumbers(){
            for (int i =0; i < numArray.length;i++){ 
                numArray[i] = ((i % 2) == 0) ? num1 : num2;
        void printNumbers(){
            for(int i=0;i<numArray.length;i++){
                System.out.println("Element "+(i+1)+": " + numArray);
    public static void main(String[] args) {
    NumArray ezPrintsArray = new NumArray();
    System.out.println("elements? ");
    try{
    ezPrintsArray.elements = System.in.read();
    catch(IOException e){
    ezPrintsArray.insertNumbers();
    ezPrintsArray.printNumbers();

    Here is what I have. At this point you are right. Basically it is not updating the elements variable. So at this point it runs, but it runs only 5 times. It is not updating the elements variable, and I have tried using this.elements, but that does not work. Help.
    * NumArray.java
    * Created on May 21, 2004, 10:22 AM
    package ArrayPackage;
    * @author  Terry
    import java.io.*;
    public class NumArray {
        int num1=1;
        int num2=0;
        int elements=5;
        int[] numArray = new int[elements];
        void getElements(){
           System.out.println("elements? ");
            try{
            elements = System.in.read();
            catch(IOException e){
        void insertNumbers(){
            for (int i =0; i < numArray.length;i++){ 
                numArray[i] = ((i % 2) == 0) ? num1 : num2;
        void printNumbers(){
            for(int i=0;i<numArray.length;i++){
                System.out.println("Element "+(i+1)+": " + numArray);
    public static void main(String[] args) {
    NumArray ezPrintsArray = new NumArray();
    ezPrintsArray.getElements();
    ezPrintsArray.insertNumbers();
    ezPrintsArray.printNumbers();

  • But I don't WANT unlimited bars!!! Help please.

    Hello all,
    I often work with short pieces of 60 seconds or less. Maybe 20 or 30 bars. Is there a way to get rid of all the rest of the bars so that, for example, when freezing a track, I don't have to wait while Logic freezes dozens of empty unneeded bars?

    Hi,
    if you look in the ruler above the arange window, you'll see a bracket at the left at measure 1 (by default). There's also a bracket like that somewhere further to the right, which is the project end marker. You can drag both markers to whatever location you want, and the freeze function will only do it's work between the begin and end marker.
    See page 150 of Help > Logic Express 8 User Manual.
    Regards,
    Jaap

  • Trying to install Logic studio 8. Says serial number is invalid. Help..

    Trying to install Logic studio 8 and it comes up with an alert saying serial number is invalid. Help please...

    Acrobat 9 is not longer supported. The serial number severs for those products are no longer available.
    Acrobat 9 Pro - Serial Number Problem - 3 Separate Licenses

  • Xcode entering input error help please

    When i run Xcode 4.5.2 on Lion and i need to enter some input (ex. cin.getline(array,10)), i need to press enter two times to keep going.
    Here is the code:    
    player1 and palindrom are arrays of char
    and here is the output:
    I enter Juan in player1 then i press [Enter] and i need to press another [Enter] if i want the prgram to continue
    and when i enter the palindrom is not stored in the array, instead the second [Enter] is stored on the palindrom array.
    Help please
    i dont know what to do i have looked on the internet but i havent found anything to solve this problem......

    You are mixing up two different ways of getting user input.
    1. getline -- a standard <stdio> function which reads user input and a return;
    2. cin -- a C++ <iostream> function which reads user input and a return.
    See http://crasseux.com/books/ctutorial/getline.html and http://www.htmlhelpcentral.com/messageboard/showthread.php?4359-C-Tutorial-1-cou t-cin for the proper way to use either one of them; you cannot use both in the same command.
    quiban92 wrote:
    i dont know what to do i have looked on the internet but i havent found anything to solve this problem......
    Those two links were the very first hits on a search for "getline tutorial" and "cin tutorial".

  • Trying to install Adobe Photodeluxe (elements 13)   I have box and cd sleeve with serial number,   But registration won't let me type letters only numbers allowed.  Help please.

    Trying to install Adobe Photodeluxe (elements 13)   I have box and cd sleeve with serial number,   But registration won't let me type letters only numbers allowed.  Help please.

    You possibly have a redemption code which has to be converted into a serial number.
    https://helpx.adobe.com/x-productkb/global/find-serial-number.html

  • Just bought Elements 13. Input serial number (starting 1057), which is not recognised and the installation stalls here. Urgent help please...

    Just bought Elements 13. Input serial number (starting 1057), which is not recognised and the installation stalls here. Urgent help please...

    Maryrhire910 I am sorry that you are facing difficulty downloading and installing Photoshop Elements 12.  Are you downloading the installation files from Download Photoshop Elements products | 13, 12, 11, 10?  If so what specific error are you receiving?

  • I need help to find the serial number for Photoshop Elements 11

    Hi! I need help to find the serial number for Photoshop Elements 11 I downloaded last year on Apple Application Store.. I have been using photoshop on mac for over a year and now need the serial number to be able to use it on macbook. I looked up Adobe's website for help but found none and noone to ask for support.. Any ideas how I can get the serial number using the App Sore bill I have?

    Please post Photoshop Elements related queries over at
    http://forums.adobe.com/community/photoshop_elements

  • Installing PS Elements 11, please help!

    Hi. I'm trying to install Elements 11 onto my laptop (Windows Vista, 4gb ram). It's my first Photoshop product. I'm using an account which is classed as an administrator.
    When it installed it said it was unable to install Shared Technologies.
    Every time I try to open the program (either from the shortcut or the Start menu) it comes up with a pop-up that says 'A problem caused the program to stop working properly' and it refuses to open at all. I don't even get the start screen or anything.
    I've tried loads of stuff in chat with two different helpers, but nothing has worked, and now I can't get back onto chat as it's not chat hours and I would really like some help. (And the chat sessions are sooo slow anyway).
    We've tried deleting files, renaming files (including OOBE to oldOOBE). I've tried downloading the Adobe application manager, but it says: Installer failed to initialize. Every time I try to do anything it says I don't have permission, even though I'm an admin. I've tried creating a new admin account and trying to access from there, but all it let me do was change the OOBE file name.
    I would like to try uninstalling the whole thing and trying again from scratch in the hope it will install better, but when I try to uninstall from the control panel it says to make sure I've deactivated the serial number to make sure I can reinstall it, but to ensure the serial number is sorted I have to actually open the program which I can't do!
    I don't know what to do Help, please?
    EDIT: When I go to eventviewer and check for photoshop errors, there are loads, an example says: Faulting application Photoshop Elements 11.0.exe, version 11.0.0.0, time stamp 0x503fc2b0, faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 0xc0000005, fault offset 0x00000000, process id 0x5d4, application start time 0x01ceaea3603591a7.

    Hi cookies-for-all,
    Please refer the kb: http://helpx.adobe.com/photoshop-elements/kb/troubleshoot-installation-photoshop-elements- premiere.html#main_Error__Below_mentioned_applications_have_failed_to_install__Shared_tech nologies_ .
    Regards,
    Romit Sinha

Maybe you are looking for

  • Could not determine BW release of logical system

    where I can verify this parameter of configuration with the BW?                                                                                Diagnosis                                                                                The control parame

  • Graphic Designer Pismo G3 Owner not sure what to do about upgrading...

    Ok. Here's the scenario. I'm running my Powerbook G3 Pismo(Firewire) 500 MHZ, 512MB ram, 20GB hard Drive. Dead Battery. Daystar Superdrive CD/DVD Burner. I also run OSX Panther 10.3.9. Most of my graphics programs are still on OS9, while I websurf an

  • Trying to install 64 bit premier elements on win7 64 bit. never works

    trying to install 64 bit premier elements on win7 64 bit. never works

  • Error in psa  quality system

    hi all, i am getting the problem with psa. 2 records i am getting worng. loading the data from r/3 system. Record 181 :0IOBJSV : Data record 181 ('0CorD '): Version '0Cor ' is not valid Record 182 :0IOBJSV : Data record 182 ('0CorE '): Version '0Cor

  • Feeling very heated...

    Hey, I have a second hand powerbook G4 (obviously..) from my best friend, whom I know took very very good care of it. Recently, it has been heating up almost to the point where i can't have it on my lap anymore because it burns. I just downloaded a p