Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JAVA program to remove all strings of even length from a list of strings. Scan the name of a file from user input

Write a JAVA program to remove all strings of even length from a list of strings.

Scan the name of a file from user input containing the strings, and two

integers, n1 and n2, representing starting and ending indices (see below).

Read in the (LARGE) file containing the strings, and output the initial size of this list.

After removing all evens, output the final list size. Finally, output all odd words from index n1 to index n2.

Your program will need to be efficient to avoid timing out.

Input/output example:

Removes strings of even length from an array.

Enter filename for file containing strings: file1.txt

Enter two indices for range of odd words to be printed out:

151770

151775

initial list.size(): 327290

final list.size(): 151780

odd words from index 151770 to 151775:

ARE

NOT

DISTRIBUTED

COMMERCIALLY.

ANY

SERVICE

*/

image text in transcribed

//My code so far: help with correcting

public class RemoveEvenStrings { public static void main(String[] args) throws FileNotFoundException { Scanner sc=new Scanner(System.in); System.out.println("Removes strings of even length from an array."); System.out.print("Enter filename for file containing strings: "); String filename=sc.nextLine(); File file = new File(filename); System.out.println("Enter two indices for range of odd words to be printed out: "); int l=sc.nextInt(); int m=sc.nextInt(); Scanner scan = new Scanner(file); ArrayList originalList = new ArrayList() ; while(scan.hasNextLine()){ originalList.add(scan.nextLine()); } System.out.println(originalList.size()); scan.close(); int n, i; n=originalList.size(); System.out.println(n); String arr[]=originalList.toArray(new String[n]); for(i=0;i Removes strings of even length from an array. Enter filename for file containing strings: HamletTitlePage.txt ENTER In Enter two indices for range of odd words to be printed out: 2 7 ENTER initial list.size(): 34 final list.size(): 18 odd words from index 2 to 7: Project cooperation in World Inc., their Library in<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago