Question
Java Sentence Capitalizer import javax.swing.JOptionPane; /** */ public class SentenceCapitalizer { public static void main (String[] args) { String input; // To hold keyboard input
Java Sentence Capitalizer
import javax.swing.JOptionPane; /**
*/
public class SentenceCapitalizer { public static void main (String[] args) { String input; // To hold keyboard input
//Get a string input = JOptionPane.showInputDialog("Enter a string.");
// Display the strng with the first letter of each // sentence capitalized JOptionPane.showMessageDialog(null, sentenceCap(input));
// Exit the application. System.exit(0); }
/** The sentenceCAp method makes a copy of a string where in the copy the first letter of each sentence is capitalized. @param str The string to perform the operation on @return A reference to the sentence-capitalized copy */
public static String sentenceCAp(String str) { // The variable i will be used to get an index // within a string. int i;
// Create a StringBuilder object initialized with // the argument String. StringBuilder temp = new StringBuilder(str);
// Capitalize the first letter. if (temp.length() > 0) temp.setCharAt(0, Character.toUpperCase(temp.charAt(0)));
// Get the index of the first period followed by a space. i = temp.indexOf(". ");
while (i != -1) { // Increment i so it refers to the position of the space. i++;
// Find the first character of the next sentence while (i < temp.length() && temp.charAt(i) == ' ') i++;
// Capitalize the character. temp.setCharAt(i, Character.toUpperCase(temp.charAt(i)));
// Get the index of the next period followed by a space i = temp.indexOf(". ", i); } return temp.toString(); } }
error: cannot find symbol JOptionPane.showMessageDialog(null, sentenceCap(input)); ^ symbol: method sentenceCap(String) location: class SentenceCapitalizer 1 error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started