Hi I'm in some serious need of help with a homework assignment. I have to write a program that takes a three word phrase from user input (through JOptionPane) and my code has to convert it to uppercase and then just take the first letter of the three words.
here is what I have so far, please help!!
import javax.swing.*;
public class ThreeLetterAcronym
{
public static void main(String[] args)
{
String phrase = JOptionPane.showInputDialog(null,
"Please enter three words.");
String acronym;
char one, two, three;
int stringLength; //stringLength is used for loop
int z; //z is reference to character placement
char c; //c is used for character value
stringLength = phrase.length();
one = phrase.charAt(0);
for(z = 0; z < stringLength; z++)
{
int a = 1;
c = phrase.charAt(z);
if(Character.isWhitespace(c))
if (a <= 1)
two = phrase.charAt(z+1);
else if(a <= 2)
three = phrase.charAt(z+1);
}
acronym = one + two + three;
JOptionPane.showMessageDialog(null, "Original words were: " +
phrase + "\nThree letter acronym is " + one + two + three);
}
}