Advertisement
marking2112

NLPartiInvitation

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