Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import java.io.*;
  2. public class Naloga5 {
  3. public static void main(String[] args) throws IOException{
  4. BufferedReader in=null;
  5. String vrstica;
  6. String Besedilo="";
  7. try{
  8. in = new BufferedReader(new FileReader("test.txt"));
  9. System.out.println("Datoteka obstaja in je odprta. Berem ..");
  10. // vse ok, beremo vrstico za vrstico, dokler ne dosežemo konca
  11.  
  12. while ( ( vrstica = in.readLine() ) != null ){
  13. //System.out.println(vrstica);
  14. Besedilo = Besedilo + vrstica;
  15. }
  16. }
  17. catch (FileNotFoundException e) {
  18. // to datoteko sproži FileReader,
  19. //če datoteke ni, zato :
  20. System.out.println("Datoteka ne obstaja");
  21. }
  22. catch ( IOException ei)
  23. {
  24. // to izjemo sproži readLine, če pride do
  25. //napake pri branju
  26. System.out.println("Napaka pri branju datoteke");
  27. }
  28. finally {
  29. // in konec - koncev je morebitno odprto datoteko potrebno zapreti
  30. if (in != null)
  31. in.close();
  32. System.out.println(Besedilo);
  33. }
  34. int Velike= 0;
  35. int Male = 0;
  36. for(int i = 0; i < Besedilo.length(); i++){
  37. if( 'A' <= Besedilo.charAt(i) && Besedilo.charAt(i) <= 'Z'){
  38. Velike++;
  39.  
  40. }
  41. else if('a' <= Besedilo.charAt(i) && Besedilo.charAt(i) <= 'z'){
  42. Male++;
  43. }
  44. }
  45. int Vse = Velike+Male;
  46. System.out.println("Velikih je:"+ Velike +" Malih je:" + Male + " Vseh je:" + Vse);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement