Advertisement
kolinsol

Java String Task 1

Dec 18th, 2016
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package task_1;
  2.  
  3. import java.io.*;
  4.  
  5. public class Strings_inerview
  6. {
  7.     public static void main(String[] args) throws IOException
  8.     {
  9.         int n=2;
  10.         char in = 'x';
  11.         String longestPol=" ";
  12.         File file = new File("/Users/kolinsol/Documents/dev/example_text.txt");
  13.         FileInputStream reader = new FileInputStream(file);
  14.         byte MyString[] = new byte[(int)file.length()];
  15.         reader.read(MyString);
  16.         String OutString = new String(MyString);
  17.         String[] OutStringArray = OutString.split(" ");
  18.         for (int i=0; i<OutStringArray.length; i++)
  19.         {
  20.             System.out.println(OutStringArray[i].length());
  21.             if(OutStringArray[i].length()>n)
  22.             {
  23.                 StringBuilder tempString = new StringBuilder(OutStringArray[i]);
  24.                 tempString.setCharAt(n, in);
  25.                 System.out.println(tempString.toString());
  26.             }
  27.             else
  28.                 System.out.println(OutStringArray[i]);
  29.         }
  30.         System.out.println(longestPol);
  31.     }    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement