Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class arabish {
- public static boolean isNumeric (String a)
- {
- if (a.matches("\\d+"))
- {
- return true;
- }
- return false;
- }
- public static String reverse (String a)
- {
- if ((null == a) || (a.length() <= 1)) {
- return a;
- }
- return new StringBuffer(a).reverse().toString();
- }
- public static void main (String[] args) throws IOException
- {
- Scanner s = new Scanner(new BufferedReader(new FileReader("DATA1.txt")));
- BufferedWriter bw = new BufferedWriter(new FileWriter("OUT1.txt"));
- for(int i = 0; i < 5; i++)
- {
- String original = reverse(s.nextLine());
- String [] split = new String [original.split("\\d+").length];
- split = original.split("\\s+");
- String out = "";
- for (int j = 0; j < split.length; j++)
- {
- if (isNumeric(split[j]))
- {
- split[j] = reverse(split[j]);
- }
- out += split[j] + " ";
- }
- if (i < 4)
- {
- bw.write(out + "\n");
- }
- else
- {
- bw.write(out);
- }
- }
- bw.close();
- }
- }
Add Comment
Please, Sign In to add comment