Question: Write a statement that declares a Scanner object and initializes it to get input from a file named input.txt. Write a statement that declares a
Write a statement that declares a Scanner object and initializes it to get input from a file named "input.txt".
Write a statement that declares a PrintWriter object an initializes it to write output to a file named "output.txt".
Provide one to two sentence answers to each of the following questions:
What happens if you try to open a file for reading that does not exist?
What happens if you try to open a file for writing that doesn't exist?
What happens if you try to open a file for writing on a device that is write-protected (such as a DVD-ROM)?
What does the following code output to the screen (see section 7.2.9 for how the printf statement works)?
| 1 2 3 4 5 6 | System.out.printf("%,6.2f %-9.9s",1000.2678,"The quick brown fox jumped"); System.out.println(); System.out.printf("%-9s $%,6.2f","The quick brown fox jumped",100.2678); System.out.println(); System.out.printf("%9s $%3.2f","The",100.2678); System.out.println(); |
Provide printf statements for each of the following. You should choose appropriate variable names given the requirements:
Display the first 15 characters of a student's last name left justified, and the student's GPA to one decimal place. The names and GPAs should line up properly in columns if you print multiple students.
Display a tax rate as a percentage to 2 decimal places, a total dollar amount purchased for purchases up to $1,000,000.00 (include the commas), and the amount of tax on that purchase (also in dollars and cents with commas). Make sure that all of the amounts line up properly in columns.
Implement (i.e., write the body of) the following method, countLines, that takes a String as a parameter. The method should open the file named by that String, count the lines in the file, close the file, and return the number of lines of text it found in that file.
public static int countLines(String fileName) throws IOException
Implement a new version of the countLines method that catches the possible IOException exception and outputs an error message if such an exception is raised.
public static int countLines(String fileName)
THis is for java thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
