This program prompts a user to enter a complete sentence (including a period). The program should read in the sentence and output a list of all letters the sentence contains in alphabetical order. It uses an array to store the letters that the program reads in from the sentence but should not contain the same letter twice. The program should then print out the letters with a comma and a space between each character. Finally, the program should print out the number of characters in the sentence (not including spaces) and the number of words in the sentence on separate lines. The following is my attempt at this. Does anyone have any comments or suggestions on my code? I don't think I did the portion correct where I am trying to print out each character only once. Also, I'm not sure how to search the string for the number of words.
Thanks for your help!!!
import java.util.Arrays;
public class Project
{
public static void main(String[] args)
{
int[] newArray = new int[100];//Initializing array
int count = 0, location = 0, numLetters = 0, numChars = 0;//Initializing variables
String input = JOptionPane.showInputDialog ("Please enter a complete sentence (using punctuation). "
inputEntered = Integer.parseInt(input);
}
{
inputArray(inputEntered, count)
}
{
int[] newArray = new int [inputArray.Length - 1];
for (i = 0 < newArray.Length - 1; i++){
newArray = inputArray;
}
}
{
printOutput(numChars, numLetters, numWords, location)
}
public static void inputArray(inputEntered, count);{
char[] inputArray = new char[100];
string inputEntered;
while string inputEntered.equals nonWhiteChar;//Put sentence in to array without doubling characters
inputArray[count] = inputEntered;
count ++;//Keep count for number of characters
}
public static void printOutput(numChars, numLetters, numWords){
Arrays.sort(newArray);//Sort Array alphabetically
While (newArray != (o){
JOptionPane.showMessageDialog(
null, newArray[location] ", "//Prints our characters with a comma separating them
location ++;
}
numLetters = count;
JOptionPane.showMessageDialog(
null, "The number of characters are: "+ numLetters);
numWords = //search string for number of words
JOptionPane.showMessageDialog(
null, "The number of words are: "+ numWords);
}
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}
Thanks for your help!!!
import java.util.Arrays;
public class Project
{
public static void main(String[] args)
{
int[] newArray = new int[100];//Initializing array
int count = 0, location = 0, numLetters = 0, numChars = 0;//Initializing variables
String input = JOptionPane.showInputDialog ("Please enter a complete sentence (using punctuation). "
inputEntered = Integer.parseInt(input);
}
{
inputArray(inputEntered, count)
}
{
int[] newArray = new int [inputArray.Length - 1];
for (i = 0 < newArray.Length - 1; i++){
newArray = inputArray;
}
}
{
printOutput(numChars, numLetters, numWords, location)
}
public static void inputArray(inputEntered, count);{
char[] inputArray = new char[100];
string inputEntered;
while string inputEntered.equals nonWhiteChar;//Put sentence in to array without doubling characters
inputArray[count] = inputEntered;
count ++;//Keep count for number of characters
}
public static void printOutput(numChars, numLetters, numWords){
Arrays.sort(newArray);//Sort Array alphabetically
While (newArray != (o){
JOptionPane.showMessageDialog(
null, newArray[location] ", "//Prints our characters with a comma separating them
location ++;
}
numLetters = count;
JOptionPane.showMessageDialog(
null, "The number of characters are: "+ numLetters);
numWords = //search string for number of words
JOptionPane.showMessageDialog(
null, "The number of words are: "+ numWords);
}
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}