Guest User

Untitled

a guest
Feb 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class arabish {
  6.     public static boolean isNumeric (String a)
  7.     {
  8.         if (a.matches("\\d+"))
  9.         {
  10.             return true;
  11.         }
  12.         return false;
  13.     }
  14.     public static String reverse (String a)
  15.     {
  16.         if ((null == a) || (a.length() <= 1)) {
  17.             return a;
  18.         }
  19.         return new StringBuffer(a).reverse().toString();
  20.     }
  21.     public static void main (String[] args) throws IOException
  22.     {
  23.         Scanner s = new Scanner(new BufferedReader(new FileReader("DATA1.txt")));
  24.         BufferedWriter bw = new BufferedWriter(new FileWriter("OUT1.txt"));
  25.         for(int i = 0; i < 5; i++)
  26.         {
  27.             String original = reverse(s.nextLine());
  28.             String [] split = new String [original.split("\\d+").length];
  29.             split = original.split("\\s+");
  30.             String out = "";
  31.             for (int j = 0; j < split.length; j++)
  32.             {
  33.                 if (isNumeric(split[j]))
  34.                 {
  35.                     split[j] = reverse(split[j]);
  36.                 }
  37.                 out += split[j] + " ";
  38.             }
  39.             if (i < 4)
  40.             {
  41.                 bw.write(out + "\n");
  42.             }
  43.             else
  44.             {
  45.                 bw.write(out);
  46.             }
  47.         }
  48.         bw.close();
  49.     }
  50. }
Add Comment
Please, Sign In to add comment