Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.regex.Pattern;
- /**
- *
- */
- /**
- * @author Criz
- *
- */
- public class RegExp {
- public static void main(String[] args) {
- Scanner scanner;
- File fileName = new File("input.txt");
- //Create Scanner and check if input file exists
- try{
- scanner = new Scanner(fileName);
- ArrayList<String> l = new ArrayList<String>();
- while (scanner.hasNextLine()){
- l.add(revertOrder(scanner.nextLine()));
- }
- for (int i=0; i < l.size();i++){
- System.out.println(l.get(i));
- }
- }
- catch (FileNotFoundException e){
- }
- }
- public static String revertOrder(String line){
- Pattern p = Pattern.compile("\t");
- String[] words = line.split(p.pattern());
- for (int i=0, j=words.length-1; i != j || i>j; i++,j--){
- String w1 = words[i];
- String w2 = words[j];
- words[i] = w2;
- words[j] = w1;
- }
- StringBuilder s = new StringBuilder();
- for(int i=0; i<words.length;i++){
- if(i == words.length-1)
- s.append(words[i]);
- else
- s.append(words[i] + "\t");
- }
- return s.toString();
- }
- }
Add Comment
Please, Sign In to add comment