Question

A Week 5 - HW-2 - Mimir Classroo X + class.mimir.io/projects/f8cd1c37-2b81-1a1c-8901-43654ace97b7 MCS 141-801 - Computer ScieCompil Reset Run Test Javador Code Coverage sar ונדען J (Untitled Elle Ech Tools Project Debugger Language Level Help New a O

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey, I have tried my best to answer your question. Still, you face any query then do tell me in comments, and also if you find the solution helpful, pls do upvote... Thanks :)

*************************************

Explanation-

In, this in order, to store the tally of each letter we can take an array of 26 length.

Array indexed from 0-25 represents the count of each character i.e

for example, arr[0] represents count of letter 'a',

arr[1] represents count of letter 'b',

'' '' ''

  arr[25] represents count of letter 'z'

CODE-

So, in the above given program,

1) after line 12, firstly declare an array of length 25

int[] arr=new int[26]; //declare new array of length 26 (for 26 characters a-z)

Arrays.fill(arr,0); //fill all the character counts to 0 initially

2) Now, on line 28, we will loop through each character of the line fetched and if the line[i] is a character, we will increment the corresponding position of that letter in arr.

for(int i=0;i<line.length();i++){

int ascii=line[i];   

arr[ascii-97]++;

}

3) Now, at line 40, print the counts of all the characters. i.e

for(int i=0;i<26;i++){

System.out.println("Count of "+ alphabet[i] + "is:" + arr[i]);

}

********************************************************************************

Add a comment
Know the answer?
Add Answer to:
A Week 5 - HW-2 - Mimir Classroo X + class.mimir.io/projects/f8cd1c37-2b81-1a1c-8901-43654ace97b7 MCS 141-801 - Computer Science...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • I need help with my computer science 2 lab. First I am asked to run the...

    I need help with my computer science 2 lab. First I am asked to run the following program and check output? public static void main(String []args) { String filename= "output.txt"; File file = new File(fileName);    try{ FileWriter fileWriter = new FileWriter(file, true); fileWriter.write("CS2: we finished the lecuter\n"); fileWriter.close(); }catch (Exception e){ system.out.println("your message"+e); } String inputfileName = "output.text"; File fileToRead = new File (inputfileName); try { Scanner = new Scanner (fileToread); while(Scanner.hasNextLine()){ String line = scanner.nextLine(); system.out.println(line); } }catch(Eception...

  • Information About This Project             In the realm of database processing, a flat file is a...

    Information About This Project             In the realm of database processing, a flat file is a text file that holds a table of records.             Here is the data file that is used in this project. The data is converted to comma    separated values ( CSV ) to allow easy reading into an array.                         Table: Consultants ID LName Fee Specialty 101 Roberts 3500 Media 102 Peters 2700 Accounting 103 Paul 1600 Media 104 Michael 2300 Web Design...

  • You will be writing some methods that will give you some practice working with Lists. Create...

    You will be writing some methods that will give you some practice working with Lists. Create a new project and create a class named List Practice in the project. Then paste in the following code: A program that prompts the user for the file names of two different lists, reads Strings from two files into Lists, and prints the contents of those lists to the console. * @author YOUR NAME HERE • @version DATE HERE import java.util.ArrayList; import java.util.List; import...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type...

    *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type in 50 words, one word per line, all words of the SAME catagory, max chars per word is 8. Example: 50 words of some names in the periodic table, or Flowers, or cars or.... 3) Save the file as myWordFile.txt Part 2 Write a program the reads the myWordFile.txt 1) Create an array of 'strings' called myWordArray 2) Write code that opens the file...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • I need help with this code This is what I need to do: Implement the Stack...

    I need help with this code This is what I need to do: Implement the Stack Class with an ArrayList instead of an array, including the following functions: • empty • push • peek • pop • overrided toString( ) function which returns all of the stack’s contents Things to note: • You no longer need a size. • You no longer need to define a constant DEFAULT_CAPACITY. Since ArrayLists grow dynamically. • Whenever possible, use ArrayList functions instead of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT