Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Scanner; import java.io.*; public class Main { // public static void main(String[] args) throws FileNotFoundException { try{ FileReader file = new FileReader(file3.txt); Scanner input
import java.util.Scanner; import java.io.*; public class Main { // public static void main(String[] args) throws FileNotFoundException { try{ FileReader file = new FileReader("file3.txt"); Scanner input = new Scanner(file); //Prints out the values in the document. Doesn't store them //while ( input.hasNext() ) // System.out.println(input.next()); //Storing values into an array String [] words = new String [1]; int i = 0; //index do{ //System.out.println(i); words[i] = input.next(); if(input.hasNext()){ //increase the size of words String [] temp = new String [words.length + 1]; for (int j = 0; j < words.length; j++) temp[j] = words[j]; words = temp; //replace the old with the new } i++; }while( input.hasNext() ); //words now holds all of the text in the document file System.out.println("Words has " + words.length + " items in it."); System.out.println("Words has " + words[0] + " as the first value."); //backwards! for (int k = words.length - 1; k >= 0; k--) { System.out.println(words[k] + " "); } //method calls go here. //end output input.close(); } catch (FileNotFoundException e){ System.out.println("File not found"); } }//ends main method //methods go below here //methods go above here }//ends the class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started