Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.lang.*;
- public class Reverse {
- public static void main(String[] args) throws FileNotFoundException, IOException {
- Scanner inFile = new Scanner(new FileReader("B-large-practice.in"));
- File outFile = new File("out.txt");
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
- String[] array = new String[0];
- String temp = "";
- int line = 0;
- int numWords = 0;
- while (inFile.hasNextLine()) {
- temp = inFile.nextLine();
- array = temp.split(" ");
- if (line >= 1) {
- out.print("Case #" + line + ": ");
- for (int i=array.length-1; i>=0; i--) {
- out.print(array[i] + " ");
- System.out.print(array[i] + " ");
- }
- }
- if (line>=1) {
- numWords += array.length;
- out.println();
- }
- line++;
- }
- out.print(" (Words = " + numWords + ")");
- out.close();
- inFile.close();
- ProcessBuilder pb = new ProcessBuilder("notepad", "out.txt");
- pb.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement