Question: Rewrite Listing 18.7, DirectorySize.java, without using recursion. Listing 1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize { public static void main(String[] args)

Rewrite Listing 18.7, DirectorySize.java, without using recursion.

Listing

1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize {

public static void main(String[] args) { 6 // Prompt the user to

enter a directory or a file System.out.print("Enter a directory or a file:

1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize { public static void main(String[] args) { 6 // Prompt the user to enter a directory or a file System.out.print("Enter a directory or a file: "); Scanner input - new Scanner (System.in); String directory = input.nextline(); 10 11 12 // Display the size System.out.printIn(getSize(new File(directory)) + " bytes"); 13

Step by Step Solution

3.34 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Output Program inputs the name of directory and outputs the size Compile javac Exercise2028ja... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!