Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The System.out object is a PrintStream and is used to output to the terminal window (screen). The java.util.Print Writer class is the primary class used

image text in transcribedimage text in transcribed

The System.out object is a PrintStream and is used to output to the terminal window (screen). The java.util.Print Writer class is the primary class used to write (print) a program's output to a file. Create Print Writer objects and use them to write program output to a file. If the file does not exist, the Print Writer instance will attempt to create it. Read: https://docs.oracle.com/javase/7/docs/api/java/io/Print Writer.html Add a new class named Print Writer Practice to your Scanner Practice project. Add a main method to your Print Writer Practice program class. Then, add the code fragment below to the main method. Try running your Print Writer Practice program. Did you forget to add the required import statements? If not, great. If you did forget, include the question "what do I need to import?" to your Java program development process and continue learning when a built-in or defined class requires an import statement. Can you find and open the output file that was created? You may have to refresh the project folder to find the file that is created. Open the file with a text-only editor. Word is not a text-only editor. Use Notepad, Sublime, TextPad, or some other text-only editor on your computer. PrintWriter pw = new PrintWriter("output.txt"); String message = "Hello World"; String s1 = String.format("output: %100 %7.2f %s", 123, 3.1415927, me ssage); String s2 = "1 + 2 = " + (1+2) + " Good-Bye!"; pw.print(s); pw.println(s2); pw.printf("Le Fin %10.4f ", Math.PI); pw.close(); Change the method and experiment to learn what each of these Print Writer methods do: print, printf, println, format, close, flush. What is the output of the above code fragment? output: 123 3.14 Hello World1 + 2 = 3 Good-Bye! Le Fin 3.1415 output: 123 3.14 Hello World 1 + 2 = 3 Good-Bye! Le Fin 3.1415927 123 3.14 Hello World1 + 2 = 3 output: Good-Bye! Le Fin 3.1416 output: 1233.14 Hello World 1 + 2 = 3 Good-Bye! Le Fin 3.1416

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 380

Answered: 1 week ago