Starting Out with Java: From Control Structures through Objects (6th Edition)
6th Edition
ISBN: 9780133957051
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 11, Problem 1FTE
Find the error in each of the following code segments:
1. catch (FileNotFoundException e)
{
System.out.println("File not found.");
}
try
{
File file = new File("MyFile.txt");
Scanner inputFile = new Scanner(file);
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java
Question #1
The following program reads integer numbers from a file named numbers.txt. For each number, the program
computes the reverse in order to check whether the number is a palindrome number or not. It then reports the
results into a file named Report.txt (A palindrome is any number whose reverse is also same, e.g., 1221, 23432, 7 , 8 are
palindromes, but 23489 is not).
Suppose the file numbers.txt contains the following numbers:
373
11
2552
5
3561
numbers.txt
Study the program carefully and answer the below questions;
Hint: you might run the program before starting answering the questions!
a) Show the output of the program. Assume that the file numbers.txt contains the data shown above
b) As the program contains nested while loop, determine how many times the following statements will
be executed: Assume that the file numbers.txt contains the data shown above
1) infile = fopen( "numbers.txt" ,"r" );
time(s)
2) printf("%d is read from the file\n" , number);
***................…
Write code that does the following: opens a file named MyName.txt, reads the first linefrom the file and displays it, and then closes the file.
Chapter 11 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Ch. 11.1 - Prob. 11.1CPCh. 11.1 - Prob. 11.2CPCh. 11.1 - Prob. 11.3CPCh. 11.1 - Prob. 11.4CPCh. 11.1 - Prob. 11.5CPCh. 11.1 - Prob. 11.6CPCh. 11.1 - Prob. 11.7CPCh. 11.1 - Prob. 11.8CPCh. 11.1 - Prob. 11.9CPCh. 11.1 - When does the code in a finally block execute?
Ch. 11.1 - What is the call stack? What is a stack trace?Ch. 11.1 - Prob. 11.12CPCh. 11.1 - Prob. 11.13CPCh. 11.1 - Prob. 11.14CPCh. 11.2 - What does the throw statement do?Ch. 11.2 - Prob. 11.16CPCh. 11.2 - Prob. 11.17CPCh. 11.2 - Prob. 11.18CPCh. 11.2 - Prob. 11.19CPCh. 11.3 - What is the difference between a text file and a...Ch. 11.3 - What classes do you use to write output to a...Ch. 11.3 - Prob. 11.22CPCh. 11.3 - What class do you use to work with random access...Ch. 11.3 - What are the two modes that a random access file...Ch. 11.3 - Prob. 11.25CPCh. 11 - Prob. 1MCCh. 11 - Prob. 2MCCh. 11 - Prob. 3MCCh. 11 - Prob. 4MCCh. 11 - FileNotFoundException inherits from __________. a....Ch. 11 - Prob. 6MCCh. 11 - Prob. 7MCCh. 11 - Prob. 8MCCh. 11 - Prob. 9MCCh. 11 - Prob. 10MCCh. 11 - Prob. 11MCCh. 11 - Prob. 12MCCh. 11 - Prob. 13MCCh. 11 - Prob. 14MCCh. 11 - Prob. 15MCCh. 11 - This is the process of converting an object to a...Ch. 11 - Prob. 17TFCh. 11 - Prob. 18TFCh. 11 - Prob. 19TFCh. 11 - True or False: You cannot have more than one catch...Ch. 11 - Prob. 21TFCh. 11 - Prob. 22TFCh. 11 - Prob. 23TFCh. 11 - Prob. 24TFCh. 11 - Find the error in each of the following code...Ch. 11 - // Assume inputFile references a Scanner object,...Ch. 11 - Prob. 3FTECh. 11 - Prob. 1AWCh. 11 - Prob. 2AWCh. 11 - Prob. 3AWCh. 11 - Prob. 4AWCh. 11 - Prob. 5AWCh. 11 - Prob. 6AWCh. 11 - The method getValueFromFile is public and returns...Ch. 11 - Prob. 8AWCh. 11 - Write a statement that creates an object that can...Ch. 11 - Write a statement that opens the file...Ch. 11 - Assume that the reference variable r refers to a...Ch. 11 - Prob. 1SACh. 11 - Prob. 2SACh. 11 - Prob. 3SACh. 11 - Prob. 4SACh. 11 - Prob. 5SACh. 11 - Prob. 6SACh. 11 - What types of objects can be thrown?Ch. 11 - Prob. 8SACh. 11 - Prob. 9SACh. 11 - Prob. 10SACh. 11 - What is the difference between a text file and a...Ch. 11 - What is the difference between a sequential access...Ch. 11 - What happens when you serialize an object? What...Ch. 11 - TestScores Class Write a class named TestScores....Ch. 11 - Prob. 2PCCh. 11 - Prob. 3PCCh. 11 - Prob. 4PCCh. 11 - Prob. 5PCCh. 11 - FileArray Class Design a class that has a static...Ch. 11 - File Encryption Filter File encryption is the...Ch. 11 - File Decryption Filter Write a program that...Ch. 11 - TestScores Modification for Serialization Modify...Ch. 11 - Prob. 10PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Assigning a value to a variable in a declaration statement is called _____. a. allocation b. initialization c. ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
What is software?
Java: An Introduction to Problem Solving and Programming (8th Edition)
In each case, the beam is subjected to the loadings shown. Draw the free-body diagram of the beam, and sketch t...
Mechanics of Materials (10th Edition)
The data shown in the following graph was collected during testing of an electromagnetic mass driver. The energ...
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Given that y=ax3+7, which of the following are correct Java statements for this equations? int y = a x x x +...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
2-1 List the five types of measurements that form the
basis of traditional ptane surveying-
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- JAVA PPROGRAM Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find matches you should print the name and the line numbers where the match was found. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name. The file may contain up to 100 names. You can use an array or ArrayList object of your choosing, however you can only have one array or ArrayList. Input validation: a) If the file does not exist, then you should display a message "File 'somefile.txt' is not found." and allow the…arrow_forwardInsert the missing code in the following code fragment. This fragment is intended to read an input file. public static void main(String[] args) String inputFileName = "dataIn.txt"; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); Select one: Oa. throws FileNotFoundException b. inherits FileNotFoundException C. catches FileNotFoundException O d. extends FileNotFoundException Next pag A 1 ENGarrow_forwardFILE* inFile = fopen("filenam.txt", "r"); Given the above code segment, which of the following would output "FILE NOT FOUND" if the file could not be opened? Group of answer choices if(inFile == NULL) { printf("FILE NOT FOUND"); } if(inFile) { printf("FILE NOT FOUND"); } if(!inFile->is_open()) { printf("FILE NOT FOUND"); } None of these ============= What does sscanf do? Group of answer choices Reads from a file Reads from a keyboard Reads from a string Writes to a screen =========== What comes first in the software development life cycle? Group of answer choices Algorithm design Identifying the problem Coding Testingarrow_forward
- #include #includecstdlib.h> int main(void){ int number , reverse = 0, digit, temp; FILE *infile, "outfile; int status; //open the input file and check if an error occurred infile = fopen( "numbers.txt" , "r" );//open the input file if(infile == NULL){ printf("Error: File \"numbers.txt\" not foundl\n"); exit (1); //open the output file and check if error occurred outfile = fopen( "Report.txt", "w" ); if(outfile == NULL)X printf("Error: File \"Report.txt\" can not be created!\n"); exit (1); status = fscanf(infile, "%d" , &number); /read first number from the file while(status != EOF){ printf("%d is read from the file\n" , number); fprintf(outfile, "%8d" , number); //To read all the numbers in the file //compute the reverse of the number temp = number ; reverse = 0; while(temp != 0)X digit = temp % 10; reverse = reverse * 10 + digit ; temp = temp/10; printf("The reverse is: %d \n", reverse); fprintf(outfile , "%8d" , reverse); //check whether the number is palindrome if(number ==…arrow_forwardJava Program ************This program must work in hypergrade and pass all the test cases.********** Chapter 9. PC #14. Word Separator (modified *** Read carefully ***) Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it line by line. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name. The file can contain one or more sentences. The program should accept as input each sentence in which all the words are run together, but the first character of each word is uppercase. Convert sentences to strings in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses.” would be converted to “Stop and smell the roses.” Sentences are separated by periods ('.'), exclamation marks ('!'), or…arrow_forwardInputOutput Class: write a program that carries out the following tasks: o Create an object of type PrintWriter and that writes into a file with the name greeting.txt. o Print the message "Hello, world!" on the file. o Close the file. o Open the same file again. o Read the message into a string variable (hint: use nextLine() method to read the text). o Print the message on the screen. AddNumbers Class: write a program that asks the user to input four floating-point numbers. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. For example, the user might enter letters instead of numbers. In this case, use the exception handling mechanism to print a proper message. (hint: use InputMismatchException) Don't forget to import java.util.*.arrow_forward
- Simple try-catch Program This lab is a simple program that demonstrates how try-catch works. You will notice the output when you enter incorrect input (for example, enter a string or double instead of an integer). Type up the code, execute and submit the results ONLY. Do at least 2 valid inputs and 1 invalid. NOTE: The program does not stop executing after it encounters an error! CODE: import java.util.Scanner; public class TryCatch Example Simple { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num = 0; System.out.println("Even number tester.\n"); System.out.println("Enter your name: "); String name = input.nextLine(); while (true) { try { System.out.println("Enter an integer : ");arrow_forwardOWrite a program that reads data from a file containing integers that ends with -999. Output the numbers that are divisible by 7 Output the numbers that are divisible by 11 Output the numbers that are not divisible by 7 or 11.arrow_forward3. Write a pseudocode that does the following: create a file, use open(), write() method returns number of characters written, and use close() to close file.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License