SlideShare a Scribd company logo
1 of 1
Download to read offline
Demonstrate your understanding of tree data structure: Write a Java program in pseudo code to
accomplish the following tasks: Identify and display the number of files in the current directory
where the file is located.
Solution
import java.io.File;
public class CurrentDirectory {
public static void main(String[] args) {
File currentDir = new File("").getAbsoluteFile();
File[] listOfFiles = currentDir.listFiles();
int count = 0;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
count++;
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
System.out
.println("Number of files in the current directory: " + count);
}
}
OUTPUT:
File .classpath
File .project
File babynamerank2006.txt
Directory bin
Directory src
Number of files in the current directory: 3

More Related Content

Similar to Demonstrate your understanding of tree data structure Write a Java .pdf

Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
Vince Vo
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 
Code error where list index is out of range when doing command like -p.docx
Code error where list index is out of range when doing command like -p.docxCode error where list index is out of range when doing command like -p.docx
Code error where list index is out of range when doing command like -p.docx
Joe7Y7Nolany
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
shahidqamar17
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
Alok Kumar
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
secunderbadtirumalgi
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 

Similar to Demonstrate your understanding of tree data structure Write a Java .pdf (20)

Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
 
Code error where list index is out of range when doing command like -p.docx
Code error where list index is out of range when doing command like -p.docxCode error where list index is out of range when doing command like -p.docx
Code error where list index is out of range when doing command like -p.docx
 
Chapter 5 Class File
Chapter 5 Class FileChapter 5 Class File
Chapter 5 Class File
 
Building a Search Engine Using Lucene
Building a Search Engine Using LuceneBuilding a Search Engine Using Lucene
Building a Search Engine Using Lucene
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBC
 
Write a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfWrite a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdf
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
JDBC
JDBCJDBC
JDBC
 
Lecture 11.pdf
Lecture 11.pdfLecture 11.pdf
Lecture 11.pdf
 

More from RAJATCHUGH12

Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
Javaa. The mean of a list of numbers is its arithmetic average. T.pdfJavaa. The mean of a list of numbers is its arithmetic average. T.pdf
Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
RAJATCHUGH12
 
vapour pressure equation The Clansius-Clapeyron relation relates the.pdf
vapour pressure equation The Clansius-Clapeyron relation relates the.pdfvapour pressure equation The Clansius-Clapeyron relation relates the.pdf
vapour pressure equation The Clansius-Clapeyron relation relates the.pdf
RAJATCHUGH12
 
The Vietnam War EraDiscuss the range of American responses to the .pdf
The Vietnam War EraDiscuss the range of American responses to the .pdfThe Vietnam War EraDiscuss the range of American responses to the .pdf
The Vietnam War EraDiscuss the range of American responses to the .pdf
RAJATCHUGH12
 
t hether each of the following statements are true or false T F Stok.pdf
t hether each of the following statements are true or false T F Stok.pdft hether each of the following statements are true or false T F Stok.pdf
t hether each of the following statements are true or false T F Stok.pdf
RAJATCHUGH12
 
Origins of psychologyWhen did it begin as a science 1879.pdf
Origins of psychologyWhen did it begin as a science 1879.pdfOrigins of psychologyWhen did it begin as a science 1879.pdf
Origins of psychologyWhen did it begin as a science 1879.pdf
RAJATCHUGH12
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
RAJATCHUGH12
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
RAJATCHUGH12
 
How does differ from evolution systematic Only cladistics traces e.pdf
How does  differ from evolution systematic  Only cladistics traces e.pdfHow does  differ from evolution systematic  Only cladistics traces e.pdf
How does differ from evolution systematic Only cladistics traces e.pdf
RAJATCHUGH12
 

More from RAJATCHUGH12 (20)

Why is the T7 polymerase gene in E. coli strain BL21(DE3) under the .pdf
Why is the T7 polymerase gene in E. coli strain BL21(DE3) under the .pdfWhy is the T7 polymerase gene in E. coli strain BL21(DE3) under the .pdf
Why is the T7 polymerase gene in E. coli strain BL21(DE3) under the .pdf
 
What type of utility program is designed to automatically make dupli.pdf
What type of utility program is designed to automatically make dupli.pdfWhat type of utility program is designed to automatically make dupli.pdf
What type of utility program is designed to automatically make dupli.pdf
 
Which of the following is true of xylem conducts water up the plant .pdf
Which of the following is true of xylem conducts water up the plant .pdfWhich of the following is true of xylem conducts water up the plant .pdf
Which of the following is true of xylem conducts water up the plant .pdf
 
What are the essential elements to have in BRDR plansWhen is a d.pdf
What are the essential elements to have in BRDR plansWhen is a d.pdfWhat are the essential elements to have in BRDR plansWhen is a d.pdf
What are the essential elements to have in BRDR plansWhen is a d.pdf
 
Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
Javaa. The mean of a list of numbers is its arithmetic average. T.pdfJavaa. The mean of a list of numbers is its arithmetic average. T.pdf
Javaa. The mean of a list of numbers is its arithmetic average. T.pdf
 
What is the characteristic of the ring of quaternionsSolutionQ.pdf
What is the characteristic of the ring of quaternionsSolutionQ.pdfWhat is the characteristic of the ring of quaternionsSolutionQ.pdf
What is the characteristic of the ring of quaternionsSolutionQ.pdf
 
What are the four basic categories of output A. Instructions, pictu.pdf
What are the four basic categories of output  A. Instructions, pictu.pdfWhat are the four basic categories of output  A. Instructions, pictu.pdf
What are the four basic categories of output A. Instructions, pictu.pdf
 
vapour pressure equation The Clansius-Clapeyron relation relates the.pdf
vapour pressure equation The Clansius-Clapeyron relation relates the.pdfvapour pressure equation The Clansius-Clapeyron relation relates the.pdf
vapour pressure equation The Clansius-Clapeyron relation relates the.pdf
 
What is a test cross and why is it used What technology is essential.pdf
What is a test cross and why is it used What technology is essential.pdfWhat is a test cross and why is it used What technology is essential.pdf
What is a test cross and why is it used What technology is essential.pdf
 
What are homologous traits a. Traits that are functional and adapti.pdf
What are homologous traits a. Traits that are functional and adapti.pdfWhat are homologous traits a. Traits that are functional and adapti.pdf
What are homologous traits a. Traits that are functional and adapti.pdf
 
The Vietnam War EraDiscuss the range of American responses to the .pdf
The Vietnam War EraDiscuss the range of American responses to the .pdfThe Vietnam War EraDiscuss the range of American responses to the .pdf
The Vietnam War EraDiscuss the range of American responses to the .pdf
 
The distance between two successive minimize of a transverse wave.pdf
The distance between two successive minimize of a transverse wave.pdfThe distance between two successive minimize of a transverse wave.pdf
The distance between two successive minimize of a transverse wave.pdf
 
t hether each of the following statements are true or false T F Stok.pdf
t hether each of the following statements are true or false T F Stok.pdft hether each of the following statements are true or false T F Stok.pdf
t hether each of the following statements are true or false T F Stok.pdf
 
Rewrite the expression as an algebraic expression of x Rewrite the .pdf
Rewrite the expression as an algebraic expression of x Rewrite the .pdfRewrite the expression as an algebraic expression of x Rewrite the .pdf
Rewrite the expression as an algebraic expression of x Rewrite the .pdf
 
Need help answering these. Underline the correct answer The fundame.pdf
Need help answering these. Underline the correct answer  The fundame.pdfNeed help answering these. Underline the correct answer  The fundame.pdf
Need help answering these. Underline the correct answer The fundame.pdf
 
Origins of psychologyWhen did it begin as a science 1879.pdf
Origins of psychologyWhen did it begin as a science 1879.pdfOrigins of psychologyWhen did it begin as a science 1879.pdf
Origins of psychologyWhen did it begin as a science 1879.pdf
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
 
In hypothesis testing, what is a Type I error Type II errorSol.pdf
In hypothesis testing, what is a Type I error Type II errorSol.pdfIn hypothesis testing, what is a Type I error Type II errorSol.pdf
In hypothesis testing, what is a Type I error Type II errorSol.pdf
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
How does differ from evolution systematic Only cladistics traces e.pdf
How does  differ from evolution systematic  Only cladistics traces e.pdfHow does  differ from evolution systematic  Only cladistics traces e.pdf
How does differ from evolution systematic Only cladistics traces e.pdf
 

Recently uploaded

Recently uploaded (20)

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

Demonstrate your understanding of tree data structure Write a Java .pdf

  • 1. Demonstrate your understanding of tree data structure: Write a Java program in pseudo code to accomplish the following tasks: Identify and display the number of files in the current directory where the file is located. Solution import java.io.File; public class CurrentDirectory { public static void main(String[] args) { File currentDir = new File("").getAbsoluteFile(); File[] listOfFiles = currentDir.listFiles(); int count = 0; for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); count++; } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } System.out .println("Number of files in the current directory: " + count); } } OUTPUT: File .classpath File .project File babynamerank2006.txt Directory bin Directory src Number of files in the current directory: 3