Advertisement
Guest User

ArrayAssignment

a guest
Nov 17th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package javaapplication8;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class JavaApplication8 {
  6.  
  7.     static Scanner sc = new Scanner (System.in);
  8.  
  9.     public static void main(String[] args) {
  10.         System.out.print("Enter a sentence: ");
  11.         String input = sc.nextLine() ;
  12.        
  13.        
  14.      
  15.        
  16.         String accum = new String()   ;
  17.         accum += input;
  18.         input = sc.nextLine();
  19.                  
  20.                
  21.         while (input!=null) {
  22.             if (input.isEmpty()){
  23.                 System.out.println("Read Enter Key.");
  24.                 break;
  25.             } else if (sc.hasNextLine()){
  26.                 input = sc.nextLine();
  27.             } else {
  28.                 input = null;
  29.             }
  30.  
  31.         }
  32.        
  33.         String sentence = input.replaceAll("\\W", "");
  34.         sentence = sentence.toUpperCase();
  35.        
  36.         int [] frequencies = new int [26];
  37.         int value = 65;
  38.         double valuecount = 0;
  39.  
  40.         for (int i = 0; i < 26 ; i++) {
  41.             for (int i2 = 0; i2 < sentence.length(); i2++){
  42.                 if (sentence.charAt(i2) == value){
  43.                     valuecount += 1 ;
  44.                 }
  45.             }
  46.             double percent = (valuecount / sentence.length() ) * 100;
  47.             char val = (char) value;
  48.             System.out.format (val + " occured %.2f percent of the time. \n", + percent);
  49.             value += 1;
  50.             valuecount =0 ;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement