Question

Write an application in java that accepts any number of String values from a user until...

Write an application in java that accepts any number of String values from a user until they enter zzz or have entered 15 strings, and display them in ascending order.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Collections;
import java.util.Scanner;
import java.util.ArrayList;

public class Strings {


    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int count = 0;
        ArrayList<String> userStrings = new ArrayList<>();

        while (count < 15) {
            System.out.print("Enter string value: ");
            String input = scanner.nextLine();
            if (input.equalsIgnoreCase("zzz")) {
                break;
            } else {
                userStrings.add(input);
            }
            count+=1;
        }
        Collections.sort(userStrings);
        for (String value : userStrings) {
            System.out.println(value);
        }

    }


}
Add a comment
Know the answer?
Add Answer to:
Write an application in java that accepts any number of String values from a user until...
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
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