In our application, we would like to mark words that could be incorrectly spelle
ID: 3723105 • Letter: I
Question
In our application, we would like to mark words that could be incorrectly spelled within a given body of text. This means that we will not be able to just read words (and discard the delimiters), but will need to make sure that every character is in some wordlet. Review the API for String Tokenizer and give an algorithm that will read a file and create wordlets. Add each wordlet to the lines display. At the end of every line, go to the next line in the lines display. Do not worry about checking the spelling AlgorithmExplanation / Answer
1)
package chegg1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class ReadFile {
public static void main(String[] args) {
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("C:\Users\cr\Desktop\data22.txt"));
while ((line = br.readLine()) != null) {
// System.out.println(line);
StringTokenizer stringTokenizer = new StringTokenizer(line, " ");
while (stringTokenizer.hasMoreElements()) {
String name = stringTokenizer.nextElement().toString();
StringBuilder sb = new StringBuilder();
sb.append(name);
System.out.print(sb.toString());
System.out.print(" ");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
2)
package chegg1;
public class StringDemo {
public static boolean isNonAlpha(String s){
int chCount=0;
int letterCount=0;
int othercount=0;
int whiteSpace=0;
for(int i=0;i<s.length();i++){
if(Character.isLetter(s.charAt(i))){
chCount++;
}else if(Character.isDigit(s.charAt(i))){
letterCount++;
}else if(Character.isSpace(s.charAt(i))){
whiteSpace++;
}else{
othercount++;
}
}
if(othercount==s.length()){
return true;
}else{
return false;
}
}
public static void main(String[] args) {
System.out.println(isNonAlpha("!!!!!"));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.