Write a program that prompts the user for a file name, assuming that the file contains a
Question:
Write a program that prompts the user for a file name, assuming that the file contains a Java program. Your program should read the file and print its contents properly indented. When you see a left-brace character ( { ) in the file, increase your indentation level by four spaces. When you see a right-brace character ( } ), decrease your indentation level by four spaces. You may assume that the file has only one opening or closing brace per line, that every block statement (such as if or for ) uses braces rather than omitting them, and that every relevant occurrence of a { or } character in the file occurs at the end of a line. Consider using a class constant for the number of spaces to indent (4), so that it can easily be changed later.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp