Question: 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

*/

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

//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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!