Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Naloga5 {
- public static void main(String[] args) throws IOException{
- BufferedReader in=null;
- String vrstica;
- String Besedilo="";
- try{
- in = new BufferedReader(new FileReader("test.txt"));
- System.out.println("Datoteka obstaja in je odprta. Berem ..");
- // vse ok, beremo vrstico za vrstico, dokler ne dosežemo konca
- while ( ( vrstica = in.readLine() ) != null ){
- //System.out.println(vrstica);
- Besedilo = Besedilo + vrstica;
- }
- }
- catch (FileNotFoundException e) {
- // to datoteko sproži FileReader,
- //če datoteke ni, zato :
- System.out.println("Datoteka ne obstaja");
- }
- catch ( IOException ei)
- {
- // to izjemo sproži readLine, če pride do
- //napake pri branju
- System.out.println("Napaka pri branju datoteke");
- }
- finally {
- // in konec - koncev je morebitno odprto datoteko potrebno zapreti
- if (in != null)
- in.close();
- System.out.println(Besedilo);
- }
- int Velike= 0;
- int Male = 0;
- for(int i = 0; i < Besedilo.length(); i++){
- if( 'A' <= Besedilo.charAt(i) && Besedilo.charAt(i) <= 'Z'){
- Velike++;
- }
- else if('a' <= Besedilo.charAt(i) && Besedilo.charAt(i) <= 'z'){
- Male++;
- }
- }
- int Vse = Velike+Male;
- System.out.println("Velikih je:"+ Velike +" Malih je:" + Male + " Vseh je:" + Vse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement