Write a JAVA program that analyzes text written in the conso

Write a JAVA program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once in the text, print out the number of times it appeared (and do so in alphabetical order). An effective way to count characters is to read from the console string-by-string, and loop through all of the characters of each of these strings. Similar to Problem a, the hasNext() method of the scanner will be useful, and when testing in Eclipse, press enter and then, once on the empty line, press CTRL-D (Mac) or CTRL+Z (Windows) when you are done typing the text. You must use an array to keep track of how many times each letter is seen in the text. The array should have 26 elements (one for each letter in the alphabet). Index 0 should be used to track the number of A’s, index 1 to track the B’s, index 2 to track the C’s, etc., up to index 25 for the Z’s. You could use a massive if/else block, but the whole reason to use arrays is to make your programs easier. So, instead, think about how to convert each character you read into the correct index and then increment that value in the array. For example, if you read an A, then you should increment the value in index 0. Specifically, you will need to determine if the character is an uppercase letter (between ‘A’ and ‘Z’), a lowercase letter (between ‘a’ and ‘z’), or something else. NO OBJECTS OR FILES USED PLEASE.

Solution

Code:

import java.util.Scanner;

class Main{

public static void main(String [] args){
String s;
int [] index=new int[26];
Scanner sc=new Scanner(System.in);
System.out.println(\"Enter the String\");
s=sc.nextLine();
  
for(String s1: s.split(\"\"))
if(s1.matches(\"[a-zA-Z]\")){
int ascii=(int)s1.toLowerCase().charAt(0);
index[ascii-97]++;
}
  
System.out.println(\"Here is the count:\");
for(int i=0;i<index.length;i++){
System.out.println(((char)(97+i))+\"-\"+index[i]);
}
}

}

OUTPUT:

Enter the String
abc def
Here is the count:
a-1
b-1
c-1
d-1
e-1
f-1
g-0
h-0
i-0
j-0
k-0
l-0
m-0
n-0
o-0
p-0
q-0
r-0
s-0
t-0
u-0
v-0
w-0
x-0
y-0
z-0

Write a JAVA program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowe
Write a JAVA program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site