Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public static final String[] kwList={"abstract","assert","boolean","break","byte","case",
  2. "catch","char","class","const","continue","default","do","double","else","enum",
  3. "extends","final","finally","float","for","goto","if","implements","import","instanceof",
  4. "int","interface","long","native","new","package","private","protected","public","return",
  5. "short","static","strictfp","super","switch","synchronized","this","throw","throws","transient",
  6. "try","void","volatile","while"};
  7. public static void analyze(){ //zadanie 3
  8. int[] occurence=new int[kwList.length];
  9. String path="TU WSADZ SCIEZKE, ROBERT PROSZE, DZIENKI";
  10. try(FileReader fr=new FileReader(path)){
  11. Scanner sc=new Scanner(fr);
  12. while (sc.hasNext()){
  13. String s=sc.next();
  14. for (int i=0; i<kwList.length; i++){
  15. if (s.equals(kwList[i]))
  16. occurence[i]++;
  17. }
  18. }
  19. sc.close();
  20. fr.close();
  21. for (int i=0; i<kwList.length; i++){
  22. if (occurence[i]>0)
  23. System.out.println(kwList[i]+" repeats "+occurence[i]+" times.");
  24. }
  25. }catch (IOException e){
  26. e.printStackTrace();
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement