Question

Write a main method that will request the user to enter Strings using a JOptionPane input...

Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”. Then, using a JOptionPane message dialog, tell the user how many of the strings contained only letters. Hint: there is a method isLetter in the wrapper class Character. in JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class LetterStrings {

    public static void main(String[] args) {
        String s;
        int count = 0;
        while (true) {
            s = JOptionPane.showInputDialog("Enter a string(STOP to exit): ");
            if (s.equals("STOP"))
                break;

            boolean foundNonLetter = false;
            for (int i = 0; i < s.length(); i++) {
                if (!Character.isLetter(s.charAt(i))) {
                    foundNonLetter = true;
                }
            }

            if (!foundNonLetter) {
                ++count;
            }
        }

        JOptionPane.showMessageDialog(null, count + " strings contains only letters");
    }
}
Add a comment
Know the answer?
Add Answer to:
Write a main method that will request the user to enter Strings using a JOptionPane input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program that will create an array of Strings with 25 elements. Input Strings...

    Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...

  • Using C# Create a “Main” method that will take user input one line at a time...

    Using C# Create a “Main” method that will take user input one line at a time until they enter the phrase “done”. Store each line entered into an ArrayList, so that one element of the ArrayList is one line of user input. You do NOT need to write your own ArrayList class, please use the standard library implementation of an ArrayList. After the user finishes typing in input, ask the user for a location and file name. Save the contents...

  • Java Question, I need a program that asks a user to input a string && then...

    Java Question, I need a program that asks a user to input a string && then asks the user to type in an index value(integer). You will use the charAt( ) method from the string class to find and output the character referenced by that index. Allow the user to repeat these actions by placing this in a loop until the user gives you an empty string. Now realize that If we call the charAt method with a bad value...

  • You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an...

    You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an array of instances of the class Book. The class Book is loaded in our Canvas files: Book.java The user will enter a number n (n must be > 0, trap the user until they input a valid value for n), Your program will declare and create an array of size n of instances of the class Book. The user will be asked to enter...

  • Write a Java program that reads a series of strings from a user until STOP is...

    Write a Java program that reads a series of strings from a user until STOP is entered. Each input consists of information about one student at the ABC Professional School. The input consists of the student’s last name (the first 15 characters with extra blanks on the right if the name is not 15 characters long), the student’s number (the next 4 characters, all digits, a number between 1000 and 5999), and the student’s program of study (one character, either...

  • Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the...

    Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the first character string from each part of a full name and return it. getSeparateName(fullName): separate a full name into first name, middle name, and last name. setMonogram(): using getInitial(), generate the right monogram result, then display it. main(String[] args): driver method Output: - Using JOptionPane to get a first name, middle name, and last name at once, then, on a JOptionPane dialog, show the...

  • JAVA Programming Produce a method that reads in a set of values (double) from the user...

    JAVA Programming Produce a method that reads in a set of values (double) from the user and returns them. Use this header: public static double[] getNumsFromUser(String msg1, String msg2) The implementation of the method should start with a message to input the total number of array elements, followed by a message to enter all the array elements. The method returns the array of elements. The two strings msg1 and msg2 that are passed to the method as parameters will be...

  • Write a Java class that examines a single character input from the keyboard. Follow this dialog...

    Write a Java class that examines a single character input from the keyboard. Follow this dialog to guide your coding: Type a single character and press Enter: m Digit: No Letter: Yes Lowercase: Yes Toggle case: M Note: There is no "next" method of the Scanner class to obtain input from the keyboard of data type char. It simply doesn't exist so you need a workaround. Store the end-user input into a String variable; then extract the first character using...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • This question is for MATLAB. Write a script that continuously asks the user for a new...

    This question is for MATLAB. Write a script that continuously asks the user for a new sentence, until the user types the word "STOP". The program records all of the sentences the user wrote (not including "STOP") in a matrix with as many rows as needed but with an N number of columns. The user is prompted to provide N before typing in the first sentence. The output of the program is the array with the sentences in it, in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT