Advertisement
Leedwon

Untitled

Jun 7th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Main {
  4.  
  5.  
  6.     private static String createAcronimFromString(String input){
  7.         StringBuilder outString = new StringBuilder();
  8.         String[] afterSplit = input.split(" ");
  9.         for(int i = 0; i < afterSplit.length; ++i){
  10.             char ch = afterSplit[i].charAt(0);
  11.             outString.append(Character.toLowerCase(ch));
  12.         }
  13.         return outString.toString();
  14.     }
  15.  
  16.     private static void myFileReader(String fileName, String phrase){
  17.         int counter = 0;
  18.         File file = new File(fileName);
  19.         BufferedReader bufferedReader = null;
  20.         try {
  21.             bufferedReader = new BufferedReader(new FileReader(file));
  22.         }  catch (FileNotFoundException ex) {
  23.             System.out.println(ex.toString());
  24.         }
  25.         String st;
  26.         if(bufferedReader != null) {
  27.             try {
  28.                 while ((st = bufferedReader.readLine()) != null) {
  29.                     counter++;
  30.                     if(counter % 2 == 0) {
  31.                         if(st.contains(phrase)){
  32.                             StringBuilder builder = new StringBuilder();
  33.                             String strings[] = st.split(phrase);
  34.                             for(int i = 0; i < strings.length; ++i){
  35.                                 if(strings[i].equals(phrase))
  36.                                     strings[i].toUpperCase();
  37.                             }
  38.                             for(int i = 0; i < strings.length; ++i){
  39.                                 builder.append(strings[i]);
  40.                             }
  41.                             System.out.println(builder.toString()); // DYBAL WAZNE: JEZELI TUTAJ MASZ WYPISYWAC TO DO PLIKU TO TO ZROB BO POLECENIE JEST STRASZNIE NIE JASNE I TA FUNCKJA TBH CHUJOWA
  42.                         }
  43.                     } else {
  44.                         for(int i = 0; i < st.length(); ++i){
  45.                             if(Character.isUpperCase(st.charAt(i))){
  46.                                 StringBuilder builder = new StringBuilder(st);
  47.                                 builder.setCharAt(i, 'm');
  48.                                 st = builder.toString();
  49.                             }
  50.                         }
  51.                         System.out.println(st); // TAK SAMO Z TYM PLIKIEM JAK WYZEJ KOMENTARZ
  52.                     }
  53.                 }
  54.             } catch (IOException ex){
  55.                 ex.printStackTrace();
  56.             }
  57.         }
  58.  
  59.     }
  60.  
  61.     public static void main(String[] args) {
  62.         String string = "test string xd";
  63.         System.out.println(createAcronimFromString(string));
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement