Write a Java application a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once.
needs, at minimum, asl user to input for the String, then show the answer ("String contains all 26 letters" or "String does not contain all 26 letters", and a button to trigger the method to determine the outcome.
Hints:
import javax.swing.*; public class ContainsAllAlphabets { public static boolean containsAllAlphabets(String s) { char ch; s = s.toLowerCase(); for (int i = 0; i < 26; i++) { ch = (char) ('a' + i); if (!s.contains(ch+"")) { return false; } } return true; } public static void main(String[] args) { String s = JOptionPane.showInputDialog("Enter a message:"); if (containsAllAlphabets(s)) { JOptionPane.showMessageDialog(null, s + " contains all alphabets"); } else { JOptionPane.showMessageDialog(null, s + " does not contains all alphabets"); } } }
Get Answers For Free
Most questions answered within 1 hours.