Advertisement
Deianov

07.4.10. Party Invitation

Oct 26th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. // 07.4.10. Party Invitation (while)
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P10a {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String input;
  9.         int countValid = 0;
  10.         int countNot = 0;
  11.         while (!(input = scanner.nextLine()).equals("Statistic")) {
  12.             input = input.toLowerCase();
  13.             boolean isValid = true;
  14.             for (int i = 0; i < input.length(); i++) {
  15.                 int c = input.charAt(i);
  16.                 if ( c < 97 || c > 122) isValid = false;
  17.             }
  18.             if (isValid) {
  19.                 System.out.println(input.substring(0, 1).toUpperCase() + input.substring(1));
  20.                 countValid++;
  21.             } else {
  22.                 System.out.println("Invalid name!");
  23.                 countNot++;
  24.             }
  25.         }
  26.         int count = countNot + countValid;
  27.         System.out.printf("Valid names are %.2f%% from %d names.%n", (double)countValid / count * 100, count);
  28.         System.out.printf("Invalid names are %.2f%% from %d names.", (double)countNot / count * 100, count);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement