Okay, the code below works fine, it prompts the user to enter a sentence, makes sure it is a proper sentence, then checks how many words there are. What I want it to do is prompt the user over and over again (keeping track of the sentences entered) until one of the sentences contains a 'q' or a 'Q'. I've been trying to put another while around the whole thing but that doesn't work. I really am stuck.
import javax.swing.*; public class ChurchAustinA2Q2 { public static void main (String [] args) { String prompt = "Enter one sentence. " ; String input ; boolean inputOk = false ; int loc ; int loc2 ; int letterCount = 0 ; int wordCount = 0 ; int charCount = 0 ; int sentenceCount = 0 ; char ch = 'x' ; input = JOptionPane.showInputDialog(null, prompt) ; input = input.trim() ; loc = input.length() ; while ( ! inputOk ){ if ( input.charAt(loc-1) == ( '!' ) ){ inputOk = true ; } else if ( input.charAt(loc-1) == ( '.' ) ){ inputOk = true ; } else if ( input.charAt(loc-1) == ( '?' ) ){ inputOk = true ; } else{ inputOk = false ; input = JOptionPane.showInputDialog(null, "That is not a proper sentence. " + prompt) ; input = input.trim() ; loc = input.length() ; } } for ( loc2 = 0 ; loc2 < input.length() ; loc2++ ){ ch = input.charAt(loc2); charCount++ ; if (( 'a' <= ch && ch < 'z' ) || ( 'A' <= ch && ch <= 'Z' ) || ( ch == 39 ) ) { letterCount++ ; } else{ if ( letterCount > 0 ){ wordCount++ ; letterCount = 0 ; } } } System.out.println("\n") ; System.out.println("Sentence Statistics ") ; System.out.println("=================== ") ; System.out.println("Sentences: " + sentenceCount) ; System.out.println("Words: " + wordCount) ; System.out.println("Word Characters: " + (charCount - wordCount) ) ; System.out.println("\n") ; System.out.println("A / a = ") ; System.out.println("E / e = ") ; System.out.println("I / i = ") ; System.out.println("O / o = ") ; System.out.println("U / u = ") ; System.out.println("\n") ; System.out.println("Average Word Length: ") ; System.out.println("Average Vowels Per Word: ") ; } }