Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package Ukrynashta;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class MainProgram {
  7. public static void main(String[] args) {
  8. Scanner fileContent = null;
  9. PrintWriter print = null;
  10. int rez=0;
  11. try
  12. {
  13. File file = new File("art.txt");
  14. if(!file.exists())
  15. throw new FileNotFoundException(); // nes file nuk ekziston e throw(gjujme 1 exception ku pastaj ekzekutohet catch
  16. fileContent=new Scanner(file);
  17. while(fileContent.hasNext())
  18. {
  19. String line=fileContent.nextLine().toUpperCase();
  20. for(char c : line.toCharArray()) // line.tocharArray e kthen string ne array te karaktereve me perdor tani ne to for loop
  21. {
  22. if(c=='B')
  23. rez++;
  24.  
  25. }
  26. }
  27.  
  28. System.out.println(rez);
  29. }
  30. catch(Exception e )
  31. {
  32. System.out.println(e.getMessage());
  33. System.out.println(e.getStackTrace());
  34.  
  35. }
  36. finally{
  37. fileContent.close();
  38. }
  39.  
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement