Advertisement
binibiningtinamoran

ReadString2

May 16th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3.  
  4. public class ReadString {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. String str;
  9. Scanner input = new Scanner(System.in);
  10.  
  11. System.out.print("Enter strings, enter DONE when finished: ");
  12. str = input.nextLine();
  13.  
  14. do {
  15. if ((str.length() > 20)) {
  16. throw new StringTooLongException();
  17. } else {
  18. System.out.print("Enter strings, enter DONE when finished: ");
  19. str = input.nextLine();
  20. }
  21. } while(!str.equalsIgnoreCase("done"));
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement