Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ukrynashta;
- import java.util.*;
- import java.io.*;
- public class MainProgram {
- public static void main(String[] args) {
- Scanner fileContent = null;
- PrintWriter print = null;
- int rez=0;
- try
- {
- File file = new File("art.txt");
- if(!file.exists())
- throw new FileNotFoundException(); // nes file nuk ekziston e throw(gjujme 1 exception ku pastaj ekzekutohet catch
- fileContent=new Scanner(file);
- while(fileContent.hasNext())
- {
- String line=fileContent.nextLine().toUpperCase();
- for(char c : line.toCharArray()) // line.tocharArray e kthen string ne array te karaktereve me perdor tani ne to for loop
- {
- if(c=='B')
- rez++;
- }
- }
- System.out.println(rez);
- }
- catch(Exception e )
- {
- System.out.println(e.getMessage());
- System.out.println(e.getStackTrace());
- }
- finally{
- fileContent.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement