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
*/
//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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started