Sentence input to array of words

I'm supposed to read an input of a sentence from the user, and then use an array to view each word separately....I'm getting an out of bounds error for the following two lines and can't figure out why or how to fix it....any help would be greatly appreciated....
import java.util.Scanner;
public class Project7A2
     public static void main(String[] args)
          String sentence, words[], result[];
          Scanner scan = new Scanner (System.in);
          System.out.print("Please enter a sentence: ");
          sentence = scan.nextLine();
          words = methods.translate (sentence);
          System.out.println(words);
import java.util.Scanner;
public class methods
public static String[] translate (String sentence)
          String temp;
          String methods[] = new String[10];
          int i=0;
          Scanner scan = new Scanner (sentence);
          temp = scan.next();
          do
               methods[i] = temp;
               i++;
          while (scan.hasNext());
          return methods;
}

I'm going to take a guess here and let me know if I'm way off base...instead of translating the sentence into an array of words should I translate the sentence into individual words and then use a loop (in the main program or a separate method) to assign each word to an array index?

Similar Messages

  • Help with converting array of sentences in to array of words.

    Hi! I'm having a problem with converting an array of sentences (about 50) into 1000 separate words into an word array. No use of tokenizers, classes (pre-made) just clear proggramming.
    Thanks in advance!

    Until you come up with a question, check these out:
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • Need help with connecting file inputs to arrays

    In this assignment I have a program that will do the following: display a list of names inputed by the user in reverse order, display any names that begin with M or m, and display any names with 5 or more letters. This is all done with arrays.
    That was the fun part. The next part requires me to take the names from a Notepad file, them through the arrays and then output them to a second Notepad file.
    Here is the original program: (view in full screen so that the code doesn't get jumbled)
    import java.io.*;       //Imports the Java library
    class progB                    //Defines class
        public static void main (String[] arguments) throws IOException
            BufferedReader keyboard;                                  //<-
            InputStreamReader reader;                                 //  Allows the program to
            reader = new InputStreamReader (System.in);               //  read the the keyboard
            keyboard = new BufferedReader (reader);                  //<-
            String name;                 //Assigns the name variable which will be parsed into...
            int newnames;               //...the integer variable for the amount of names.
            int order = 0;              //The integer variable that will be used to set the array size
            String[] array;             //Dynamic array (empty)
            System.out.println (" How many names do you want to input?");   //This will get the number that will later define the array
            name = keyboard.readLine ();
            newnames = Integer.parseInt (name);                                         // Converts the String into the Integer variable
            array = new String [newnames];                                               //This defines the size of the array
            DataInput Imp = new DataInputStream (System.in);       //Allows data to be input into the array
            String temp;                                       
            int length;                                                                  //Defines the length of the array for a loop later on
                for (order = 0 ; order < newnames ; order++)                                //<-
                {                                                                           //  Takes the inputed names and
                    System.out.println (" Please input name ");                            //  gives them a number according to
                    temp = keyboard.readLine ();                                           //  the order they were inputed in
                    array [order] = temp;                                                  //<-
                for (order = newnames - 1 ; order >= 0 ; order--)                                //<-
                {                                                                                //  Outputs the names in the reverse 
                    System.out.print (" \n ");                                                   //  order that they were inputed
                    System.out.println (" Name " + order + " is " + array [order]);             //<-
                for (order = 0 ; order < newnames ; order++)                                  //<-
                    if (array [order].startsWith ("M") || array [order].startsWith ("m"))     //  Finds and outputs any and all
                    {                                                                         //  names that begin with M or m
                        System.out.print (" \n ");                                            //
                        System.out.println (array [order] + (" starts with M or m"));         //
                    }                                                                         //<-
                for (order = 0 ; order < newnames ; order++)                                            //<-
                    length = array [order].length ();                                                   //
                    if (length >= 5)                                                                    //  Finds and outputs names
                    {                                                                                  //  with 5 or more letters
                        System.out.print (" \n ");                                                      //
                        System.out.println ("Name " + array [order] + " have 5 or more letters ");      //<-
    }The notepad file contains the following names:
    jim
    laruie
    tim
    timothy
    manny
    joseph
    matty
    amanda
    I have tried various methods but the one thing that really gets me is the fact that i can't find a way to connect the names to the arrays. Opening the file with FileInputStream is easy enough but using the names and then outputing them is quite hard. (unless i'm thinking too hard and there really is a simple method)

    By "connect", do you just mean you want to put the names into an array?
    array[0] = "jim"
    array[1] = "laruie"
    and so on?
    That shouldn't be difficult at all, provided you know how to open a file for reading, and how to read a line of text from it. You can just read the line of text, put it in the array position you want, until the file is exhausted. Then open a file for writing, loop through the array, and write a line.
    What part of all that do you need help with?

  • Input and array

    anyone can guide me with this?
    I got a String input from user.."012345601234567890abc..."
    i wan the string to be put inside an array...
    with the first array having only "0123456" (6 characters)
    And the second string having only "01234567890" (10 characters)
    the third one having "abc..." (10 characters)
    ....till all characters are put inside string.
    anyone can help?

    input = //get the input;
    String array[] = {input.substring(0, 6), input.substring(7, 18),
                      input.substring(19, 30)};
    there you go mate.

  • How to input a 64 -bit word ???

    Hi
    Since I am new to LabVIEW programming, I desperately need your
    suggestions.
    I have to implement a cluster in which there are unsigned bit words
    (8-bit word, 16-bit word, 24-bit and 64-bit word). In the control
    palette, I could find the representation for 8, 16 and 32-bit signed
    or Unsigned. What should I do if I have to implement a 24-bit or a
    64-bit word?
    Eagerly waiting for your reply.
    Thanks in advance
    Regards
    Rajesh
    [email protected]

    Hi,
    Thanks for ur reply.
    TO detail my application bit more.. I have to use the 64-bit word (9 X
    64-bit word) in the FPGA to calculate the modulating frequency. The
    FPGA part is not interesting here. I have the set of 64-bit pattern
    which is being used in the FPGA code. In the near future, I might want
    to change the bit pattern frequently and hence I want to implement a
    VI, where I can change the 64-bit pattern and not to change the
    pattern in FPGA. So i tried to implement a cluster where I would input
    the bit pattern (whole 64 bit word) and drive the word to the FPGA
    throught the microcontroller.
    Hope I dont need any calculation to be performed in the VI.
    |--------| from VI |-------| |---------|
    | 64 bit |------------>| uC |--------->| FPGA |
    |--------| |-------| |---------|
    Is that possible to find a solution which would help me???
    Thanks in advance.
    Regards
    Rajesh
    altenbach wrote in message news:<[email protected]>...
    > There is no native LabVIEW support for 64bit integers.
    >
    > What kind of application is this? Do you just need to (a) shuffle the
    > values around, or (b) do actual math and comparison operations on
    > them?
    >
    > Case (a) is easy and you can use anything you like for 64 bits (8
    > character string, Arrays of 8xU8, 4xU16, or 2xU32, etc.)
    > Case (b) is more difficult, because you need to implement your own
    > math, comparison, and formatting operations. You could internally
    > represent the U64 number as above, as cluster of 2 U32s, or similar.
    >
    > Infinite precision arithmetic is not hard. Look at some of the recent
    > LabVIEW zone coding challenges, e.g. for
    > href=http://www.ni.com/devzone/lvzone/codechallenge6_results.htm>factorials
    > or
    > href=http://www.ni.com/devzone/lvzone/codechallenge4_results.htm>Vampire
    > numbers. U64 would seem even simpler.
    >
    > 24 bits fit in a U32, so you just need to possibly check for 24 bit
    > overflow (in this case e.g. "number (logical AND)
    > b11111111000000000000000000000000)" is not equal zero).
    >
    > Tell us a bit more about your application.

  • Check variable against an array of words

    Hi,
    I wish to check a variable for a number of words that are in
    a array.
    Not sure if this is the best way to do it, but this is what i
    have.
    I have my own counter system that counts every visitor, but
    some of these visits are from BOTS, spiders..
    So i wish to have a method of searching the HTTP_USER_AGENT
    for certain words i put in a array.
    What i am after is how i get the words in an array and how i
    then get the script to check the HTTP_USER_AGENT for a word in the
    array and if so it will not complete the script. (not add to the
    counter)
    if none of the words are in the HTTP_USER_AGENT then it will
    add to the counter.
    so something like?
    <?
    // do array
    // check if HTTP_USER_AGENT contains a word from array
    if () {
    // increase counter if none of the words are in
    HTTP_USER_AGENT
    include(increase.php);
    ?>
    its the bit between the if () that i have no idea about, any
    help would be great.
    cheers in advance for your help.
    Jason

    not very clever wrote:
    > this is a bit more about what i am trying to do.
    >
    > <?
    > // do array
    > array(1)="something";
    > array(2)="something else";
    > array(3)=..
    > ..
    > ..
    >
    >
    > $HTTP_USER_AGENT = contants of the HTTP_USER_AGENT
    > // check if HTTP_USER_AGENT contains a word from array
    > if (array(x) is in the string $HTTP_USER_AGENT) {
    > // increase counter if none of the words are in
    HTTP_USER_AGENT
    > include(increase.php);
    > }
    >
    > ?>
    >
    >
    $myArray = array('blip','blop','glup',...);
    $counter = 0;
    foreach($myArray as $mA){
    if(preg_match('/'.$mA.'/',$HTTP_USER_AGENT)){
    $counter++;
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    Downloads: Slide Show, Directory Browser, Mailing List

  • Adf input complex arrays error

    I have web service that contains array of complex type as input. I want to invoke web service from jspx page using adf. I have added web service data control and followed this guide [http://www.oracle.com/technetwork/developer-tools/adf/learnmore/54-ws-complex-input-type-169197.pdf] to add input form into jspx page, But I have table for array input. In PageDef.xml page, I have updated NDValue according to the pdf tutorial, now it is
    <NamedData NDName="refSys"
    NDValue="#{bindings.theIterator.currentRow.dataProvider}"
    NDType="java.lang.Object[]"/>
    But, when ever I click on submit button it gives following error:
    Cannot create an object of type:[Ljava.lang.Object; from type:java.util.HashMap
    How can I cope with this problem?
    I am using JDeveloper 11gR1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi,
    with respect to my previously posted thread, its hard to understand that oracle does not support complex type arrays,
    let me rephrase the question again :
    I have a complex type as the following:
    <xs:complexType name="updateRefSys">
    <xs:sequence>
    <xs:element name="id" type="xs:string" minOccurs="0"/>
    <xs:element name="refSys" type="tns:refSys" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="refSys">
    <xs:sequence>
    <xs:element name="pltfrm" type="xs:string" minOccurs="0"/>
    <xs:element name="custNo" type="xs:string" minOccurs="0"/>
    <xs:element name="ExtSys" type="xs:string" minOccurs="0"/>
    </xs:sequence>
    </xs:complexType>
    It contains a refsys which is a complex type which may contain zero or many elements, this complex type is an input to my web service, what I need to know is that how can i copy rows from adf table into this complex type so that I may pass this parameter to the web service.

  • Input/Output Arrays

    Hello,
    I am new to Java, and have just recently started learning it. I am student working with a math prof, and I need help with a program that would help our research.
    First of all, is it possilbe to input numbers from a textfile which just contains numbers like so:
    1
    2
    3
    4
    5
    6
    Into an 2x3 array, like [1 2 3]
    [4 5 6]
    Could someone help me with the code? Once I have these saved into an array then I am able (with my limited Java knowledge) to do what I need to do with the arrays, it is just a question of transfering the numbers in the first place.
    Thanks to anyone who could help, as you'd save me a great deal of time.
    Mike Lukas

    Mike this is not a problem that is specific to Java, nor any other language really, but rather is a type of problem that would be assigned in an introductory programming class.
    In my time at college I took my options in Math, and I assure you that there are many Math students that know how to solve this problem and then implement it in Java.
    Take a look at basic loops and how they work and indexing methods. That is about all the help I will render for you, until you get your own code and post it.

  • Japanese input Kotoeri Maverick Register Word menu not visible

    Hi,
    I would like to add words to Kotoeri japanese dictionnary, but the menu Flag/Register word is not visible, I tried alt but on succès
    Any idea?
    Best regards

    Ok So I asked on the Japanese Fourms and this is the answer I got back. To be honest I had tried this on my work computer before and it did not work but it is working on my home computer so maybe this will help you.
    Mavericks (OS 10.9)ではことえりのユーザ辞書の仕様が変わりました。
    The way you do this action has changed with the change to Maveriks.
    1)まず、ことえり入力メソッドを追加する必要があります。
    Make sure that you have added the Kotoeri Method (I think you have)
         → Add the Kotoeri input method
    2)既に追加済みであれば、こちらのヘルプをご確認下さい。
    Next use the below link to help you add words to your dictionary.
         → Add words and symbols to a user dictionary
    Pretty much you add things to your dictionary like you would add shortcut word like (R) becomes ®.
    1. While using Kotoeri, choose Edit Text Substitutions from the Input menu (looks like a flag or character) in the menu bar.
    2. In the text pane of Keyboard preferences, click Add to add a word.
    3. Type the hiragana reading of the word in the Replace field. Readings of registered words can be no longer than 32 characters. If you’re registering an adjective, make sure to enter the reading in its dictionary form. The ending must be 〜い (~i). For example, あたらしい (atarashii) or たかい (takai). If you’re registering an adverb, don’t include inflective endings, such as 〜な (-na) or 〜だ (-da).
    4. Click the With column, then type the replacement word in the With field.A word can be no longer than 64 characters.
    Hope this helps you out. I will have to wait until Tuesday to find out if it works on my work computer.
    Happy Chinese New Year.

  • Clustering an array of words

    Hi, I have a large array of over 5000 words. I need to take all these words and re list them by groups--e.g. have words like 'fire', 'flame', 'burn' and 'combustible' listed next to each other.
    Is there a thesaurus I can use to perform this operation? I would like to be able to use the thesaurus in SQL Server 2005. Is this possible?
    I appreciate any help or comments that are given--thanks in advance!

    I wonder if a list is really the data structure you want. This sounds more like a mesh structure to me...
    But I have no idea how you would program that. I can think of a number of annoying implementation problems, like: is there any way to search through such a mesh?
    You should check the algorithm forum for that.

  • Numerical Input and array

    Hello, I have a labview program with a numerical input for frequency. I created an array that contain a series of numbers. How can I let the program to get each element from the array sequentially? For example, it will read the first element of the array. 2 seconds later it will read the second element so on. I try to use "index array" but it only gives me one specific element of that array. Any ideas?
    Thanks
    Message Edited by lxx on 04-20-2006 10:05 PM
    Message Edited by lxx on 04-20-2006 10:06 PM

    Hello Ixx,
    From taking a look at  your program, as far as I can tell, the
    code inside the loop is creating a pulse train, and using another
    single pulse generation task to control how long to generate the
    initial pulse train.  The Wait + (ms) VI is used to prevent the
    tasks from going directly from being started to being cleared, and they
    are a necessary part if you want your program to output as many pulses
    at each frequency that you have entered into the 'number of pulses'
    control on the front panel.  It seems that if you want to try to
    transition between these different frequencies more smoothly, you
    should generate more intermediate frequencies by increasing the
    'Samples' input of the Ramp Pattern VI.  If you want to include
    more intermediate frequencies, but want to transition from your lowest
    frequency to highest in the same amount of time, then you will have to
    generate less pulses at each frequency by lowering the value in the
    'number of pulses' control.
    Have you considered programming with NI-DAQmx functions as opposed to
    these Traditional NI-DAQ functions?  They are much easier to use
    and actually perform better in almost all applications.  NI-DAQmx
    requires that you have LabVIEW 7.0 or later, and that your DAQ device
    is new enough to support it, which you can check here.
    I hope this helps!
    Regards,
    Travis G.
    Applications Engineering
    National Instruments
    www.ni.com/support

  • Store uncertain number of input into array

    Hi, I am new to java, and while I do a practice of store input input array I got a question like this:
    If we want to use array, we must create the array, and that require we give the size of the array.
    For example, if I know I will have ten integer input, I can just store those in an array like : int [] intArray = new int [10];
    But what if we are not sure about the number of inputs, it might be 10, it might be 20.
    Can I create an array with a uncertain size? Or I should not use array to store the input?

    797233 wrote:
    Hi, I am new to java, and while I do a practice of store input input array I got a question like this:
    If we want to use array, we must create the array, and that require we give the size of the array.
    For example, if I know I will have ten integer input, I can just store those in an array like : int [] intArray = new int [10];
    But what if we are not sure about the number of inputs, it might be 10, it might be 20.
    Can I create an array with a uncertain size? Or I should not use array to store the input?No you cannot declare an array with an uncertain size. What you can do is utilize the java.util.ArrayList class. (http://download.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html) If you want to be a super trooper you can create your own simple class that creates and disposes of array objects depending how how many elements you need.

  • Prompt input into Array

    Before I begin, I'm saying sorry again to everyone I have offended. But I need your help for this one.
    I just need to understand this:
    Prompting user to input integers into a set of array; let's say
    int number[] = new num[5];I'm going to do something like this But stuck.
    String num[] = JOptionPane.showInputDialog( "Please enter the number:");I'm stuck however we input numbers into array. i've read the textbook but all the examples were just numbers already in the array. Not the inputting part.
    Can you say something?

    Here's my update. I am missing the String?
    import javax.swing.JOptionPane;
    public class GetArray {
    public static void main (String[] args) {
    int[] number = new int[5];
    for(int i=0;i<number.length;i++)
    number=Integer.parseInt(JOptionPane.showInputDialog( "Please enter the number:"));
    JOptionPane.showMessageDialog(null, " The numbers are: " + number[i], " Answer ", JOptionPane.PLAIN_MESSAGE );
    Error I'm getting from this is:cannot find symbol variable i
    for line
    JOptionPane.showMessageDialog(null, " The numbers are: " + number[i], " Answer ", JOptionPane.PLAIN_MESSAGE );
    Please can anyone solve this?
    Thank you,
    C.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Simple question: Can you input an array of strings directly into your plot legend instead of "Plot 0", "Plot 1"......?

    I have an array of channel names for a simple vi I wrote and I want to input them into the plot legend.  I typically use ring controls to allow different users to select what they want to see, but beyond 3 or 4 it gets confusing.  Is there a way to take an array of strings and input them directly into the legend string slots using a property node?  I have spent hours searching to no avail.
    Thanks!!
    Adam

    Yes, of course there is! Try this:
    Message Edited by altenbach on 05-01-2009 08:45 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    PlotNamesII.png ‏7 KB

  • Allow boolean arrays as input for "Array Min & Max"

    The Array Max & Min function is quite versatile, but for some reason it does not accept boolean arrays. This restriction make no sense at all. Since we can easily sort boolean arrays, this function should work too! It would come in handy for example if looking for the position of a single TRUE in a 2D array (search only works for 1D arrays!). Array min & max would simply return the index pair of the first TRUE found. As a workaround, we currently need to insert a "boolean to 0,1" to get the same effect. This seems unecessary.

    > I have to disagree with the need to do this LabVIEW prides itself of function polymorphism, but there are these nagging little holes that give you a broken wire for no obvious reason at all. Sure there are workarounds, but the beginner programmer might construct a horrible Rube Goldberg style workaround, full of duct tape and bailing wire. We can sort boolean arrays so there is a clear order between TRUE and FALSE ---> there is a MAX and a MIN and the function should return it. Note that Array Min&Max even works for string arrays, where it outputs the lexically sorted first and last array element. (Hey, I did not know that, could be useful sometimes!). Not allowing boolean array inputs is an unnatural exception and should be fixed.  A similar case is described in this suggestion (which did not get much attention either)

Maybe you are looking for

  • Migrating SQL Reporting Services error

    Hi I followed this technet documentation for migrating the reporting services database and temp database to a new server. I got the error here below ... what i was trying to do is create a new folder however it's throwing out an error and not letting

  • Editing a Pre-Made template

    I bought a premade flash template, however as of now it is created in non-flash format. I would love to have my top piece as the flash that it was meant to be. My site is currently http://www.georgiavideoproductions.com and the way that it should loo

  • How i can connect my home theather on my sound blaster extern

    hello. I bought a sound blaster li've 24 external, i have vista, and i have a sony 5. home theather. I want to hear all my speakers on 5. . I conected the home theather through a digital optic cable, but when i?make a test, i only hear the front left

  • Grid Control reliance on Flash

    Folks, Currently investigating whether it is possible to get full functionality from grid control 11g without Adobe Flash and plugin being installed. Reason for request is security concerns about enabling flash internally here. If not possible is the

  • IMac G5 & Leopard 10.5

    Ok So I Just Got My First Mac As A Present (iMac G5) & Its On 10.3.9 ( IM SUPER HAPPY ! ) I NEED To Install 10.5 Because I just Cant Deal With This Old School Version ! I Need You Guys To Give Me Some Ways In Doing So. I Have Tryed: 1. Burning A Dvd