1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line, for equality. Print any lines that are not equivalent indicating the line numbers in both files. The language of implementation is java
2 . Create a program that reads a string input from the user, then determines and prints how many of each lowercase vowels (a, e. i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also count and print the number of non-vowel characters.
/* * Java Program for comparing two files */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { String fileName1 = "file1.txt"; String fileName2 = "file2.txt"; BufferedReader reader1 = new BufferedReader(new FileReader(fileName1)); BufferedReader reader2 = new BufferedReader(new FileReader(fileName2)); String line1 = reader1.readLine(); String line2 = reader2.readLine(); boolean areEqual = true; int lineNum = 1; while (line1 != null || line2 != null) { if(line1 == null || line2 == null) { areEqual = false; break; } else if(! line1.equalsIgnoreCase(line2)) { areEqual = false; break; } line1 = reader1.readLine(); line2 = reader2.readLine(); lineNum++; } // ignoring end of file line lineNum--; if(areEqual) { System.out.println("The number of lines: " + lineNum); System.out.println("Two files have the same content."); } else { System.out.println("Two files have different content. They differ at line " + lineNum); } reader1.close(); reader2.close(); } }
Note: For queries, drop me a comment.
Get Answers For Free
Most questions answered within 1 hours.