computer science

Hey I have three questions with creating these methods, thanks.

Write a Function
You will be given one of the following problems to solve using and writing Java functions.

Given a list of words, return an array which indicates the frequency that each letter occurs. For example, in the list [”apple”, ”bob”], [ ’a’ -> 1, ’b’->2, ’e’->1, ’l’->1, ’o’->, ’p’->2] . The order of the array does not matter and a Frequency class will be provided.

Given a list of words, indicate whether the list constitutes a ”Word Lad- der.” A Word Ladder is a series of words where each succeeding word changes by only one letter. You may not assume that all words will be of the same length, and you may not assume the length of the list.

Given an integer greater than 2, X, return an array populated with all prime numbers up to and including X.

  1. 👍
  2. 👎
  3. 👁
  1. 1.
    Check with your teacher if the list is supposed to be case sensitive. From the context of the question, it should not be.
    In this case, convert all the strings into lowercase and compare using the String.toLowerCase() method before comparison.
    The comparison can be done character by character using the String.charAt(i) method.
    Use an array of size 26 to store the frequencies. Do not forget to initialize the array (or the Frequency class values).
    Read the Java API for more details.
    or to download the API to your computer:

    1. 👍
    2. 👎
  2. 2.
    First compare the lengths of the successive words using String.length().
    If they equal, then compare letter by letter, and count the number of different letters. If the difference equals 1, continue the "ladder".
    You may have to convert all letters to lowercase before the comparison.

    3. There are plenty of algorithms for finding prime numbers. One of them is to test the divisibility by primes. You will have to create a list of primes, starting with 2, which is assumed to be a prime. Test all odd numbers starting from 3. Whenever you find that the number does not divide by the numbers on your prime list, you have found a prime, and add it to your prime list.

    For example 3 does not divide by 2, so add 3 to the prime list. 5 does not divide by 2 and 3, add it to the prime list. Likewise, 7 is added to the prime list. 9 divides by 3, so skip it.
    11 does not divide by 2,3... so it is a prime.

    You do not have to test all the primes on the prime list. If the square of the prime on the prime list exceeds the number X to be tested, X can be declared a prime. For example, for 11, it is not divisible by 2,3, but 5²>11, so 11 can be declared a prime.

    It may sound complicated, if you post your pseudocode or the Java code, you can get further help.

    1. 👍
    2. 👎

Respond to this Question

First Name

Your Response

Similar Questions

  1. english, can you check over my answers? thanks!

    I have answered these questions, but would like someone to review them.. can you please check the answers that i've chosen? thanks in advance! Identify the function of the infinitive in the sentence. Choose from the following:

  2. Algebra

    Write a function rule to represent the sequence. 0.3, 0.9, 1.5, 2.1,... A(n) = 0.6 + (n - 1)0.3 A(n) = 0.6 - (n)0.3 A(n) = 0.3 + (n - 1)0.6 A(n) = 0.3 + (n + 1)0.6 Write a function rule to represent the sequence. 47, 32, 17, 2,...

  3. ****college algebra…radical functions****

    Create a rational function such that the graph of has vertical asymptotes at x=5 and x= -7, a hole at x=2 , and a horizontal asymptote at y = 14. By creating a rational function, you are to write rule for this function. There are

  4. MATH

    15. Write a function rule that represents y is 5 less than the product of 4 and x. 16. Write a function rule that represents 7 less than three fifths of b is a. 17. Write a function rule that represents the almond extract a

  1. Literary Analysis Unit Test

    hey y,all! all you need to do is look at my answers I think they're all correct but I am not sure to please look over them. my answer and questions are coming...

  2. Science

    Hi, I have two questions about biology I need help with. 1) Some questions fall outside the realm of science, which of the following questions could not be answered using the scientific method? A)What is the function of the

  3. math project.. PLEASE HELP!!

    The municipal swimming pool in Nicetown has three different ways of paying for individual open swimming. Evan is trying to decide which way to pay. • Early Pay: Pay $45 before Memorial Day; swim any number of days • Deposit

  4. math

    The following set of points belong to a specific function: {(-3,0)(-2,4), (-1,0), (0,-6),(1,-8), (2,0),(3,24)} Based on the set of points answer the following questions: a) What type of function does it produce? Justify your

  1. Math

    Hey everyone!! please help.. Find a function f such that the graph of f has a horizontal tangent at (1,0) and f"(x)=10x?? Thanks

  2. Jiskha

    I typed several questions and answers regarding the subject of Geography, and suddenly, as I was waiting for a reply from Ms. Sue, it seemed as though my questions were deleted from the webpage where all of the other questions are

  3. algebra

    3. write the function whose graph is the graph of y=sqrt of x, but is shifted to the left 3 units y=____ 4. write the function whose graph is the graph of y=|x|, but is shifted down 8 units y=___ 5. write the function whose graph

  4. algebra

    I have a few questions that I don't understand hope someone can help. 1)write an equation of th line, in point slope form, that passes through the two given points. (-17,8),(3,-2) I figured (y-8)=-2(x+17) not sure 2) the graph of

You can view more similar questions or ask a new question.