Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 12.11, Problem 12.11.2CP

Explanation of Solution

The given code is,

//Class definition

public class Test

{

//Main method

public static void main(String[] args) throws Exception

{

//Create object for PrintWriter class by open the //file with file name

java.io.PrintWriter output = new java.io.PrintWriter( "temp.txt" );

//Write the values into text file

output.printf( "amount is %f %e\r\n", 32.32 , 32.32);

//Write the values into text file

output.printf( "amount is %5.4f %5.4e\r\n" , 32.32 , 32.32);

//Check the condition 1 is greater than 2 and //writes the result into text file

output.printf( "%6b\r\n" , (1 > 2)) ;

//Write the text into text file

output.printf( "%6s\r\n" , "Java" ) ;

//Close the text file

output...

Blurred answer
Students have asked these similar questions
JAVA Given a main program that searches for the ID or the name of a student from a text file, complete the findID() and the findName() methods that return the corresponding information of a student. Then, insert a try/catch statement in main() to catch any exceptions thrown by findID() or findName(), and output the exception message. Each line in the text file contains the name and the ID of a student, separated by a space. Method findID() takes two parameters, a student's name and a Scanner object containing the text file's contents. Method findID() returns the ID associated with the student's name if the name is in the file, otherwise the method throws an Exception object with the message "Student ID not found for studentName", where studentName is the name of the student. Method findName() takes two parameters, a student's ID and a Scanner object containing the text file's contents. Method findName() returns the name associated with the student's ID if the ID is in the file,…
4.) How many times is the println statement executed? for (int i = 0; i < 10; i++) for (int j = 0; j <= 5; j++) System.out.println(i * j) a. 100 b. 60 c. 50 d. 45 5.) Will the following program terminate? int balance = 10; while (true) { if (balance < 9) break; balance = balance - 9; } a.Yes   b. No 6.) What exception type does the following program throw? public class Test { public static void main(String[] args) { System.out.println(1 / 0); } } a. ArithmeticException b. ArrayIndexOutOfBoundsException c. StringIndexOutOfBoundsException d. ClassCastException e. No exception
I have to create a Java program that lets the user interact with it, so they can learn about exceptions. How do I let the user interact with a list of options and direct them to a catch statement?  Here is my program so far:  import java.util.Scanner;import java.io.*;import java.util.InputMismatchException; public class Exceptions{              public static void main(String[] args)throws IOException{              // declare variables      char option = 'y';            //Arithhmetic & Array TEST      int array[] = {10,20,30,40};      int num1 = 50;      int num2 = 10;               // Setting up scanner to get user data      Scanner exc = new Scanner(System.in);            // Main method (menu, try-catch block)         // all within a loop         try {          }      // I want to learn how an ArrayIndexOutOfBoundsException...         catch(ArrayIndexOutOfBoundsException exception) {            System.out.println("This exception is thrown when the array index that was entered is…

Chapter 12 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education