Answer:
Code details below
Step-by-step explanation:
// Scanner is a class in the java.util package used to get the entry of primitive types like int, double etc. and also String.
import java.util.Scanner;
// The program must be able to open any text file specified by the user, and analyze the frequency of verbal ticks in the text.
public class TextAnalyzer {
// public : it is a access specifier that means it will be accessed by publically. static : it is access modifier that means when the java program is load then it will create the space in memory automatically. void : it is a return type i.e it does not return any value. main() : it is a method or a function name.
public static void main(String[] args) {
// the program will find the length of a string without using any loops and you may assume that the length of entered string is always less than any given number
Scanner scan = new Scanner(System.in);
System.out.println("Enter a sentence or phrase: ");
String s = scan.nextLine();
System.out.println("You entered: "+s);
int numOfCharacters = getNumOfCharacters(s);
System.out.println("");
System.out.println("Number of characters: "+numOfCharacters);
outputWithoutWhitespace(s);
}
public static int getNumOfCharacters(final String s){
int numOfCharCount = 0;
for(int i=0; i<s.length();i++){
numOfCharCount++;
}
return numOfCharCount;
}
// Using this function, we replace all whitespace with no space(“”)
public static void outputWithoutWhitespace(String s){
String str = "";
for(int i=0; i<s.length();i++){
char ch = s.charAt(i);
if(ch != ' ' && ch != '\t')
str = str + ch;
}
System.out.println("String with no whitespace: "+str);
}
}