Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final String[] kwList={"abstract","assert","boolean","break","byte","case",
- "catch","char","class","const","continue","default","do","double","else","enum",
- "extends","final","finally","float","for","goto","if","implements","import","instanceof",
- "int","interface","long","native","new","package","private","protected","public","return",
- "short","static","strictfp","super","switch","synchronized","this","throw","throws","transient",
- "try","void","volatile","while"};
- public static void analyze(){ //zadanie 3
- int[] occurence=new int[kwList.length];
- String path="TU WSADZ SCIEZKE, ROBERT PROSZE, DZIENKI";
- try(FileReader fr=new FileReader(path)){
- Scanner sc=new Scanner(fr);
- while (sc.hasNext()){
- String s=sc.next();
- for (int i=0; i<kwList.length; i++){
- if (s.equals(kwList[i]))
- occurence[i]++;
- }
- }
- sc.close();
- fr.close();
- for (int i=0; i<kwList.length; i++){
- if (occurence[i]>0)
- System.out.println(kwList[i]+" repeats "+occurence[i]+" times.");
- }
- }catch (IOException e){
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement