Write a Java program that will read in one or more lines of text and then determ
ID: 3767502 • Letter: W
Question
Write a Java program that will read in one or more lines of text and then determine the following:
The number of uppercase letters in the text.
The number of lowercase letters in the text.
The number of digits in the text.
The number of whitespace characters (i.e., blanks or newlines) in the text.
The number of other, non-letter, non-digit, non-whitespace characters in the text.
After reading the text, the program should display the text followed by a display of all of the above statistics.
Suggestions and hints:
Use a String variable to read the text into (since you do not know in advance how much text will be input).
The nextLine() method from Scanner class can be used to read in more than one line into a String variable. To do this, inform user to type multiple lines of text before hitting the “Enter” key on the computer.
You will need to use methods from wrapper class Character.
Explanation / Answer
Program:
import java.util.Scanner;
public class MyPragraph {
@SuppressWarnings("resource")
public static void main(String arg[])
{
System.out.println("Enter the paragraph : ");
Scanner sca;
String[] text=new String[1000];
int i=0;
sca=new Scanner(System.in);
while(true) {
String nextLine = sca.nextLine();
if ( nextLine.equals("") ) {
break;
}
text[i] = nextLine;
i++;
}
int n=0;
System.out.println(" ");
while(n<i)
{
System.out.println(text[n]);
n++;
}
}
}
Result:
In ancient manuscripts, another means to divide sentences in into paragraphs was a line break (newline) followed by an initial at the beginning of the next paragraph. An initial is an oversize capital letter, sometimes outdented beyond the margin of text. This style can be seen, for example, in the original Old English manuscript of Beowulf. Outdenting is still used in English typography, though not commonly.[4] Modern English typography usually indicates a new paragraph by indenting the first line. This style can be seen in the (handwritten) United States Constitution from 1787. For additional ornamentation, a hedera leaf or other symbol can be added to the inter-paragraph whitespace, or put in the indentation space.
In ancient manuscripts, another means to divide sentences in into paragraphs was a line break (newline) followed by an initial at the beginning of the next paragraph. An initial is an oversize capital letter, sometimes outdented beyond the margin of text. This style can be seen, for example, in the original Old English manuscript of Beowulf. Outdenting is still used in English typography, though not commonly.[4] Modern English typography usually indicates a new paragraph by indenting the first line. This style can be seen in the (handwritten) United States Constitution from 1787. For additional ornamentation, a hedera leaf or other symbol can be added to the inter-paragraph whitespace, or put in the indentation space.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.