Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.00 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.lang.*;
  4.  
  5. public class Reverse {
  6.  
  7.     public static void main(String[] args) throws FileNotFoundException, IOException {
  8.        
  9.         Scanner inFile = new Scanner(new FileReader("B-large-practice.in"));
  10.         File outFile = new File("out.txt");
  11.         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
  12.        
  13.         String[] array = new String[0];
  14.         String temp = "";
  15.         int line = 0;
  16.         int numWords = 0;
  17.        
  18.         while (inFile.hasNextLine()) {
  19.             temp = inFile.nextLine();
  20.             array = temp.split(" ");
  21.             if (line >= 1) {
  22.                 out.print("Case #" + line + ": ");
  23.                 for (int i=array.length-1; i>=0; i--) {
  24.                     out.print(array[i] + " ");
  25.                     System.out.print(array[i] + " ");
  26.                 }
  27.             }
  28.             if (line>=1) {
  29.                 numWords += array.length;
  30.                 out.println();
  31.             }
  32.             line++;
  33.         }
  34.         out.print(" (Words = " + numWords + ")");
  35.         out.close();
  36.         inFile.close();
  37.         ProcessBuilder pb = new ProcessBuilder("notepad", "out.txt");
  38.         pb.start();
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement