CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Beginner array questions. Random letters and comparing word against those in array

  1. #1
    Join Date
    Jan 2021
    Posts
    1

    Beginner array questions. Random letters and comparing word against those in array

    Hi guys, new to the forum and very new to Java. Am using textpad, unsure of the version that is being used.

    I have to create a programm for an assignment and could use help with two elements as I am not overly familiar with arrays. Firstly, I need an array that generates 10 random letters from a-z allowing duplicates. The array only has one dimension. I've found some suggestions online but to be honest I'm not overly sure of the logic behind the answers I've seen. New to the forum so unsure of how to hyperlink those.

    The second problem I'm finding more complex. I need to store words within an array and compare an inputted word against them.I'm fine with managing the input but unsure of how to A. compare the word against those in the array and B. What type of array to use. I was planning on using a Sting[] but unsure if this is correct as I'm aware there are other types of arrays but unsure of how to use them.

    Any help or fingers pointing in the right direction would be much appreciated

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,870

    Re: Beginner array questions. Random letters and comparing word against those in arra

    need an array that generates 10 random letters
    Arrays do not generate values. They contain values. If the letters are Strings of length 1 then a String[] would work.
    If the letters will be char then char[] would work.
    One way To get random letters would be to define a String with all the letters and then generate a random index into that String and use the String class's charAt method. See the Random class's nextInt method for a way to generate the random index.

    For searching an array for a match, use a loop to access each element in the array. Then use the String class's equals() method to compare the item in the array against the inputted word.
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)