Simple program with array do not want to compile

Please do not laugh but I wrote the following program to create a array of
strings. The program do not want to compile and I can not see why.
Can somebody please tell me what I am doing wrong.
class MyArrayOfStrings5
puplic static void main(String[] args)
String[] anArray;
anArray = new String[5];
System.out.println("Value at index 2 is: " + anArray[2]);
}

Firstly thank you very much for responding to my cry of help. Saying that, I am a little
confused about the fact that "new String" is being used for declaration and initialisation.
1. String[] anArray = new String[5];
I understand that this is telling me that variable anArray will contain String values and will
be a array of 5
2. anArray = new String();
This is the one that is confusing me. Am I correct to assume that
(because it is in a for loop) for every position in the array we are assigning
String() to the variable anArray. Why do we need the new command before
String()?

Similar Messages

  • Simple question with arrays

    Im a couple days new in java, Ive been searching for an answer for hours and havent found a solution.
    This is the mistake it shows (when trying to use any element of the array):
    array required, but java.util.ArrayList <java.lang.String> found
    The array is:
    public static ArrayList<String> numList = new ArrayList<String>();
    Im filling it this way: (so that it contains each word of a file in separate)
    BufferedReader br = new BufferedReader(new FileReader("Archivo.txt"));
    try
    while(true)
    String aLine = br.readLine();
    if(aLine == null) throw new EOFException("Le?do todo el archivo.");
    if(!aLine.equals(""))
    StringTokenizer st = new StringTokenizer(aLine);
    while(st.hasMoreTokens())
    numList.add(st.nextToken());
    }catch(EOFException e)
    The problem comes when I try to use the elements of the array (in specific when trying to convert each element of the array to int, so that i can do math operations with them).
    for example:
    for (a=0; w>a; a++)
    int x = Integer.parseInt(numList[a])
    Can anyone help me with this? (where is the mistake and how to convert from string array elements to int)
    Thank you // Muchas Gracias

    The trouble is that you're confusing ArrayLists with arrays. They're not the same thing.
    Currently you're making an ArrayList. If you want an array of String, do this:
    String[] myArray = new String[50];
    int i = 0;
    while(st.hasMoreTokens()) {
      myArray[i] = st.nextToken();
      i++;
    }Or perhaps better yet:
    String[] numListArray = numList.toArray(new String[0]);But you really don't need an array for what you're doing. Use an Iterator.
    Iterator<String> strings = numList.iterator();
    while(strings.hasNext()) {
      int x = Integer.parseInt(strings.next());
    }You get the idea. Read the Collections tutorial about iterators. Read the language spec about arrays. Also look at the java.util.Arrays class.

  • How to run a simple program with main?

    I have a simple class with main, something like the following:
    public static void main(String[] args) {
    Is it possible to run / execute this main from within workshop?

    In SP2 we've made it very easy to automatically set the main class name
    when you first try to run a class in a Java project that doesn't have
    already have debugging configured.
    More generalized ways to easily run a class with a main method are
    already on the list for the next release.
    Thanks for the feedback,
    Josh
    Carl wrote:
    Thanks, that worked:)
    Workshop should consider dealing with simple classes with main much
    simpler...
    "Josh Eckels" <[email protected]> wrote in message
    news:3f96f8c1$[email protected]..
    Yes, you can run and debug it, but it needs to be in a Java project. If
    it's not already in one, create a new Java project and copy in the
    source. Go to the Project Properties, and select the Debugger settings.
    Enter the class that contains the main method. If you'd like, you can
    set the checkbox for Build before Debugging so that you are always
    running off the current source code.
    You should then be able to run the project after building it.
    Josh
    Carl wrote:
    I have a simple class with main, something like the following:
    public static void main(String[] args) {
    Is it possible to run / execute this main from within workshop?

  • Problem with arrays - variable not been inicializes

    I've declared my array ;
    int[] array ;
    int intefer;
    BufferedReader stdin = new BufferedReader(new InputStreamReader( System.in ));
    intefer = stdin.readLine();
    array[0] = intefer; --> variable array might not have been initialized.
    Can you please help me ? Why is the error occuring ?

    array[0] = intefer; --> variable array might not have been initialized.
    Can you please help me ? Why is the error occuring ?An array is an object; all object should be instantiated by use of the 'new'
    operator. You never instantiated such an object and therefore never
    initialized your 'array' variable.
    kind regards,
    Jos

  • 'Hello' does not want to compile and interpret

    I recently downloaded the latest JDK Update 12 from the sun website.
    I typed the basic hello program. The problem is in the compiling and interpreting of the program. In the command prompt, I made a new directory(folder) titled javacoding; in which I also saved the source code for the hello world program. After which i switched to it and I set the path of bin containing the compiler and interpreter to this directory. I typed in the following; javac Hello.java.
    I set the path thus: C:\javacoding> set path =%path%;C:\Program Files\Java\jdk1.6.0_11\bin;.;
    However, the program does not compile and the following message is displayed instead:
    'javac' is not recognized as an internal or external command, operable program or batch file.
    Here is a sample of the program I typed
    class Hello
    /*This program displays Hello*/
    public static void main (String args[])
    //This is the main method
    System.out.println("Hello, World!");
    For the record this was done on a Vista system.
    Thank you.

    Melanie_Green wrote:
    Variable ___________ Value
    Path ______________ C:\Program Files\Java\jdk1.6.0_11\bin;
    // Set this for both user and system variable*@Mel:* Ummm. Not to be too rude, but I'm almost certain that's incorrect, or atleast sub-optimal.
    Presuming that the OP (that's you Ikenna) is a system administrator on there own box, then just set the system PATH... all users will pick it up from there... also setting at the user-level just appends a useless duplicate entry to the PATH, slowing down (unsucessful) path-searches... not that you'd notice.
    *@OP:* Show us a dir of your jdk-bin directory... we'll need the exact command and it's output (at least down to javac.exe)... Question is: Is that directory exactly what's in your PATH? so also show us the command and output of echo %PATH% ... just post the whole command session (typos and all) between a pair of &#123;code} tags.
    Cheers. Keith.

  • Simple program with Java KeyTool

    Hello!
    I tried to create signature using keytool to send data using ssl. I create private key file by
    keytool -genkey -keystore kkm.kst -storepass passwd -alias kkmcert -keypass passwd -keyalg RSA -keysize 1024 -sigalg MD5WithRSA -validity 365 -dname CN=tester
    and then I tried to signature string "test" by following code:
    public static void getSign(){
                 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
                 String keyStoreFile = "kkm.kst";
                 FileInputStream fis = new FileInputStream(keyStoreFile);
                 String keyStorePassword = "passwd";
                 keyStore.load(fis, keyStorePassword.toCharArray());
                 fis.close();
                 String myKeyAlias = "kkmcert";
                 String myKeyPassword = "passwd";
                   PrivateKey privateKey = (PrivateKey) keyStore.getKey(myKeyAlias, myKeyPassword.toCharArray());
                 if(privateKey == null) throw new Exception("Client key not found");
                 String text = "test";
                  Signature signature = Signature.getInstance("MD5withRSA");
                  signature.initSign(privateKey);
                  byte [] data;
                       data = text.getBytes("UTF-8");
                 signature.update(data);
                 byte [] sign = signature.sign();
                 String signString = new String(sign, "UTF-8");
                 System.out.println(signString);
    }After that I tried to verify that derived signature isn't wrong:
    keytool -import -keystore kkm.kst -storepass passwd -file certfile.cer -alias ep -noprompt
    public static void checkSign(String signString){
                 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
                 String keyStoreFile = "kkm.kst";
                 FileInputStream fis = new FileInputStream(keyStoreFile);
                 String keyStorePassword = "passwd";
                 keyStore.load(fis, keyStorePassword.toCharArray());
                 fis.close();
                 String eportAlias = "ep";
                 Certificate cert = keyStore.getCertificate(eportAlias);
                 if(cert == null) throw new Exception("Server certificate not found");
                 PublicKey publicKey = cert.getPublicKey();
                 String text = "test";
                  byte [] data;
                  try {
                       data = text.getBytes("UTF-8");
                  } catch (UnsupportedEncodingException e) {
                       data = text.getBytes();
                  String subscriptText = signString;
                  byte [] subscript = signString.getBytes();
                  try {
                       Signature signature = Signature.getInstance("MD5withRSA");
                      signature.initVerify(publicKey);
                      signature.update(data);
                      System.out.println(signature.verify(subscript) ? "RIGHT": "WRONG");
                  } catch (Exception e) {
                       System.out.println("Exc : WRONG");
              } catch (Exception e) {
                   System.err.println("Error");
                   e.printStackTrace();
    }And after checking I got message "WRONG" that means that generated signature is wrong signature. =( Can anybody help me to find error?

    hey buddy... i am stucked with one more error.
    when the same code was compiled and during the running of the code it says that
    error : error reading in E:\oracle\ora90\network\admin\listener.ora; java.util.zip.ZipException execption
    i saw environment variable, but still for all i couldn't get rid of this problem ..needed help badly!

  • I have a program that I do not want to update, how do I turn off nags

    The Mac App Store keeps sending me reminders to update iMovie 10.   I am using the superior iMovie 06.  How can I tell the app store to stop notifying me about iMovie 10 updates.
    Thanks

    This is the iMovie site.   Scan through this.
    https://discussions.apple.com/community/ilife/imovie/content?filterID=contentsta tus%5Bpublished%5D~objecttype~objecttype%5Bthread%5D
    I will happily ask the hosts to move your post to this site where it may get the attention of the Gurus there, if you like.   But I think you have enough points and the level to report the post yourself and ask them to move it.   Let me know if I can help.

  • Why is Adobe bombarding me with software I do not want?

    Virtually every time I open a new window on Firefox, Adobe tells me to update Flashplayer.  When I click OK the subsequent window tells me I am downloading Flashplayer and another program.  I DO NOT want the other program, nor do I want to change my home page or get a new tool bar.  Why can I simply update the outdated software without all the other SPAM you think I need?

    Are seeing this?

  • Why can't there be a simple program to setup remote file sharing?

    If someone wants to take a crack at getting my Time Capsule available remotely (off network over internet), I would appreciate it.
    I am a graphic designer and use the other side of my brain. DNS, static IP, MAC address etc is very confusing.
    I purchased a neat little app called Connect360 for Mac that automatically configures music/video sharing to Xbox360 from MacBook Pro. Evrything is automatic. Brilliant. If someone could do that to configure internet file sharing, it would be worth $$$$$$.
    Thanks

    You cannot do a simple program with the multiplicity of internet connections, modem type, ISP types, authentication types. Also you notice that Apple decided everything should now happen from the cloud, so cancelled the mobileme service which did offer easier setup for something that is far more limited, at least for now.
    Also please note there are fridge mechanics who fix fridges and car mechanics who fix cars. Photographers who make a living taking better photos than I can, and computer technicians who do network setups. If you don't fix your car or the washing machine.. why do you need to fix your internet networking?? Pay someone to do it.. but Steve said computers are easy and you got a false impression that everything should just plug together and work.. well it doesn't. Find a tame Computer tech and let him/her carry that part of your business. Spend your time doing what earns you money instead of in frustration at fixing the fridge. (Being symbolic of the computer network).
    It is rather like when I (a computer technician) dabble in graphic design.. I do, and you laugh at the results.. !!
    Please note I no longer work in that field because the pay is miserable, the customers ring up day and night and scream at you that the network is down and it is all your fault, and want you to spend an hour on the phone helping them. No service fee of course. You should on the basis of a single job, help connect their computer to the printer over the phone for an hour, rather than pay you a service call. Since computers are easy and you should just donate your time and life really to helping them do what Steve and Bill said was so easy.

  • ABAP program created in one system want to trigger from other system

    Hello,
    I have created ABAP program in ECC server internally it is using function module to update table.This ABAP program has 2 variants.
    I wnat to trigger this ABAP program from BW . How to idenfied an abap program which is return in system1 into other system2.So that it can be executed from BI.
    Thanks.

    There are ways to do this.
    Create an RFC in R/3 system (Tcode: se37 or read forums for sample). Create an event in sm62 (choose customer event) - then schedule your R/3 program (with whatever variant you want) in R/3 to trigger it when the event raised.
    Within the RFC (R/3), you need to trigger the event -
    Raise event to execute background jobs running under this event id
    w_eventid type btceventid value 'ZCUSTOMEVENT'.
        call function 'BP_EVENT_RAISE'
          exporting
            eventid                = w_eventid
          exceptions
            bad_eventid            = 1
            eventid_does_not_exist = 2
            eventid_missing        = 3
            raise_failed           = 4
            others                 = 5.
        if sy-subrc <> 0.
        endif.
    in BW - Create a program - Call the RFC (created in R/3). You can even add this to your process chains.
    CALL FUNCTION 'Z_RFC_IN_R3'
          DESTINATION p_dest
          IMPORTING
          XYZ = XYZ
          TABLES
          IT_X = IT_X
    p_dest being your R3 destination (this is RFC maintained in sm59 for your R3 client)....
    Good luck. Quite a bit of work but works perfect.

  • HT1535 I Do NOT want to download items from my library. HOW do i STOP them from downloading, and NEVER downloading again?

    I have gone in and "hidden" the items. But I have a very large movie, and a large translation program, that I Do NOT want on my phone (OR on my computer), but every time I open iTunes, it automatically starts downloading both these items. (plus all the apps, that I NO Longer want on my phone).
    I don't care if the items are hidden. as long as they STOP downloading, every time i turn iTunes on.

    When you connect your phones to iTunes, select your iPhones and then click on the app button and simply select the apps you want to have on your phone.
    You can also delet the applications you dont want by simply opening applcation in iTunes and then deleting them and moving them to trash.

  • I want to install foxfire but i do not want it to install on my default browser which is safari? I have installed before and every thing I do is foxfire. i do not want that.. please help

    I want to install foxfire for a specific program. I do not want foxfire to replace my other browsers. I the past I have installed foxfire, and it becomes my browser for everything. I do not want this to happen.. please help
    == User Agent ==
    Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16

    When you are asked if you want Firefox to be your Default Browser, just say '''no'''. And also check the box that you don't want to be asked every time you open Firefox.

  • Export contacts in CSV, Excel or other format.  I DO NOT want to sync with an email account.  This is for an exemployee who just wants names and numbers in a simple format.

    I have the iPhone 4S, iOS7.0 of an ex-employee.  That person would like a list of their contacts from the phone.  I DO NOT want to sync with another email account, just a simple listing of the contacts.

    Also consider using
    Export Address Book
    By Stefan Keller
    Free, via App Store. Works like a charm. See here for details and link to App Store
    https://www.subclassed.com/apps/export-address-book/details

  • I want to save with alt s in the program Exact Online. This function is not working. this is the first time that i use this program with firefox.

    Question
    I want to save with <nowiki><alt><s></nowiki> in the program Exact Online. This function is not working. this is the first time that i use this program with firefox.
    '''edit''', mod escaped the '''<nowiki><s></nowiki>''' to prevent line through question

    Submitted too soon... To change your accelerator key for accesskeys to Alt alone (or a different combination), you can change a setting using Firefox's about:config preferences page.
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the filter box, type or paste '''ui.k''' and pause while the list is filtered
    (3) Make sure '''ui.key.generalAccessKey''' is set to its default value of -1 (or right-click and choose Reset if it is not).
    (4) Double-click '''ui.key.contentAccess''' to open a dialog box to change the value from its current default (on Windows, 5) to your choice of the following:
    * 2 = '''Ctrl''' (Fx default on Mac thru Fx13)
    * 3 = Ctrl + Shift
    * 4 = '''Alt''' (IE/Chrome/Safari default on Win/Linux)
    * 5 = '''Alt + Shift''' (Fx default on Windows & Linux)
    * 6 = '''Ctrl + Alt''' (Fx default on Mac from Fx14) (Chrome/Safari default on Mac)
    * 7 = Ctrl + Alt + Shift
    This should take effect as soon as you OK the dialog, so you can experiment in a separate tab. Other combinations are available if you want to try them. See http://kb.mozillazine.org/Ui.key.contentAccess (inaccessible at the moment?)

  • I am using a Mac Leopard and want to know if I upgrade to Snow Leopard (so I can use the new Lightroom 4) will any of my programs be affected.  I will not be able to restore some software and want to know if I'll lose those programs with the upgrade?

    I am using a Mac Leopard and want to know if I upgrade to Snow Leopard (so I can use the new Lightroom 4) will any of my programs be affected.  I will not be able to restore some software and want to know if I'll lose those programs with the upgrade?

    Hello,
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 4GB at least)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    It looks like they do still have it:
    http://store.apple.com/us/product/MC573Z/A?fnode=MTY1NDAzOA
    And it's been reported that if you have a MobileMe account Apple will send one free.
    If it's a core Duo & not a Core2Duo, then it'll only run in 32 bit mode.

Maybe you are looking for