SlideShare a Scribd company logo
Use Java to program the following.
1. Create public java class named Benford.
2. It's main function should prompt for the name of a data file and then the function iterates
through the all of the elements in the data file and computes the frequency (count and
percentage) of the first number in each entry.
3. Note: Some of the data files have comments that you must filter out.
4. Also note: that blank lines or lines where the number begins or is 0 must also be filtered out.
5. Your output must be formatted as follows.
Solution
Hi Firend, Please find my code.
Please let me know in case of any issue.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class CountFrequency {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
// taking input file name
System.out.print("Enter input file name: ");
String fileName = sc.next();
// opening input file
Scanner inputFile = new Scanner(new File(fileName));
// declaring array to store count of first digit of each entery
int[] frequency = new int[10];
int totalCount = 0; // to maintain total count
int num;
// reading all lines
while(inputFile.hasNextLine()){
// reading current line
String line = inputFile.nextLine();
// if line is not empty
if(line == null || line.isEmpty() || line.trim() == "")
continue;
// taking first character of current line
char firstDigit = line.charAt(0);
// if first character is digit and not equal to 0
if(Character.isDigit(firstDigit) && firstDigit != '0'){
// converting first character of current line in integer
int d = firstDigit - '0';
frequency[d]++;
totalCount++;
}
}
System.out.println("DigittCounttFrequency");
for(int i=1; i<=9; i++){
System.out.println(i+"t"+frequency[i]+"t"+
((double)frequency[i]/(double)totalCount*100));
}
}
}
/*
Sample run:
##### Entry of input.txt:
453 43
//543
123
0
4ee
875
52
// Output
Enter input file name: input.txt
Digit Count Frequency
1 1 20.0
2 0 0.0
3 0 0.0
4 2 40.0
5 1 20.0
6 0 0.0
7 0 0.0
8 1 20.0
9 0 0.0
*/

More Related Content

Similar to Use Java to program the following.1. Create public java class name.pdf

Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
noreendchesterton753
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdf
udit652068
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
SudhanshiBakre1
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
deepaksatrker
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
theodorelove43763
 
Write a program that reads a file containing text- Read each line and.docx
Write a program that reads a file containing text- Read each line and.docxWrite a program that reads a file containing text- Read each line and.docx
Write a program that reads a file containing text- Read each line and.docx
lez31palka
 
Assignment 2Assignment Content1. Top of FormResource·.docx
Assignment 2Assignment Content1. Top of FormResource·.docxAssignment 2Assignment Content1. Top of FormResource·.docx
Assignment 2Assignment Content1. Top of FormResource·.docx
braycarissa250
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
BG Java EE Course
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
michael1810
 
Write a program that will count the number of characters- words- and l.docx
Write a program that will count the number of characters- words- and l.docxWrite a program that will count the number of characters- words- and l.docx
Write a program that will count the number of characters- words- and l.docx
lez31palka
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
kanchanmahajan23
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
kanchanmahajan23
 
Java session08
Java session08Java session08
Java session08Niit Care
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
Saifur Rahman
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
Danairat Thanabodithammachari
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
WebStackAcademy
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 

Similar to Use Java to program the following.1. Create public java class name.pdf (20)

Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdf
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
 
IO and threads Java
IO and threads JavaIO and threads Java
IO and threads Java
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
CORE JAVA-1
CORE JAVA-1CORE JAVA-1
CORE JAVA-1
 
Write a program that reads a file containing text- Read each line and.docx
Write a program that reads a file containing text- Read each line and.docxWrite a program that reads a file containing text- Read each line and.docx
Write a program that reads a file containing text- Read each line and.docx
 
Assignment 2Assignment Content1. Top of FormResource·.docx
Assignment 2Assignment Content1. Top of FormResource·.docxAssignment 2Assignment Content1. Top of FormResource·.docx
Assignment 2Assignment Content1. Top of FormResource·.docx
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
Write a program that will count the number of characters- words- and l.docx
Write a program that will count the number of characters- words- and l.docxWrite a program that will count the number of characters- words- and l.docx
Write a program that will count the number of characters- words- and l.docx
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
 
What is java input and output stream?
What is java input and output stream?What is java input and output stream?
What is java input and output stream?
 
Java session08
Java session08Java session08
Java session08
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 

More from f3apparelsonline

How do the microsporangium and microspore in seed plants differ from.pdf
How do the microsporangium and microspore in seed plants differ from.pdfHow do the microsporangium and microspore in seed plants differ from.pdf
How do the microsporangium and microspore in seed plants differ from.pdf
f3apparelsonline
 
Homework question with 2 partsA. Compare and contrast the geologic.pdf
Homework question with 2 partsA. Compare and contrast the geologic.pdfHomework question with 2 partsA. Compare and contrast the geologic.pdf
Homework question with 2 partsA. Compare and contrast the geologic.pdf
f3apparelsonline
 
Client Business Risk The risk that the client will fail to achieve it.pdf
Client Business Risk The risk that the client will fail to achieve it.pdfClient Business Risk The risk that the client will fail to achieve it.pdf
Client Business Risk The risk that the client will fail to achieve it.pdf
f3apparelsonline
 
Describe how removing water from a hydrophobic binding site or ligan.pdf
Describe how removing water from a hydrophobic binding site or ligan.pdfDescribe how removing water from a hydrophobic binding site or ligan.pdf
Describe how removing water from a hydrophobic binding site or ligan.pdf
f3apparelsonline
 
create a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdfcreate a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdf
f3apparelsonline
 
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdf
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdfCase Project 7-1 commen, diicrerne functions, arii price. wri.pdf
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdf
f3apparelsonline
 
Base your answer to questio n 25 on the map below and on your knowled.pdf
Base your answer to questio n 25 on the map below and on your knowled.pdfBase your answer to questio n 25 on the map below and on your knowled.pdf
Base your answer to questio n 25 on the map below and on your knowled.pdf
f3apparelsonline
 
As presented, the tree summation algorithm was always illustrated wi.pdf
As presented, the tree summation algorithm was always illustrated wi.pdfAs presented, the tree summation algorithm was always illustrated wi.pdf
As presented, the tree summation algorithm was always illustrated wi.pdf
f3apparelsonline
 
A person who quits a job in Los Angeles to look for work in Chicago i.pdf
A person who quits a job in Los Angeles to look for work in Chicago i.pdfA person who quits a job in Los Angeles to look for work in Chicago i.pdf
A person who quits a job in Los Angeles to look for work in Chicago i.pdf
f3apparelsonline
 
4. Which one of the following is a key disadvantage of a a. As a gene.pdf
4. Which one of the following is a key disadvantage of a a. As a gene.pdf4. Which one of the following is a key disadvantage of a a. As a gene.pdf
4. Which one of the following is a key disadvantage of a a. As a gene.pdf
f3apparelsonline
 
Who are the three agencies today that rate bondsHow do the three .pdf
Who are the three agencies today that rate bondsHow do the three .pdfWho are the three agencies today that rate bondsHow do the three .pdf
Who are the three agencies today that rate bondsHow do the three .pdf
f3apparelsonline
 
Which of the following is trueChimpanzees and hominids share a comm.pdf
Which of the following is trueChimpanzees and hominids share a comm.pdfWhich of the following is trueChimpanzees and hominids share a comm.pdf
Which of the following is trueChimpanzees and hominids share a comm.pdf
f3apparelsonline
 
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdfWhat does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
f3apparelsonline
 
What is the firm’s cost of preferred stock Please show work in Exce.pdf
What is the firm’s cost of preferred stock Please show work in Exce.pdfWhat is the firm’s cost of preferred stock Please show work in Exce.pdf
What is the firm’s cost of preferred stock Please show work in Exce.pdf
f3apparelsonline
 
What are the 2 major cytoskeletal classes that participate in cell d.pdf
What are the 2 major cytoskeletal classes that participate in cell d.pdfWhat are the 2 major cytoskeletal classes that participate in cell d.pdf
What are the 2 major cytoskeletal classes that participate in cell d.pdf
f3apparelsonline
 
Wanda is a 20 percent owner of Video Associates, which is treated as.pdf
Wanda is a 20 percent owner of Video Associates, which is treated as.pdfWanda is a 20 percent owner of Video Associates, which is treated as.pdf
Wanda is a 20 percent owner of Video Associates, which is treated as.pdf
f3apparelsonline
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
f3apparelsonline
 
To design an expert system, we must first identify a problem to be s.pdf
To design an expert system, we must first identify a problem to be s.pdfTo design an expert system, we must first identify a problem to be s.pdf
To design an expert system, we must first identify a problem to be s.pdf
f3apparelsonline
 
Translate the following into English. Let C denote an arbitrary coll.pdf
Translate the following into English. Let C denote an arbitrary coll.pdfTranslate the following into English. Let C denote an arbitrary coll.pdf
Translate the following into English. Let C denote an arbitrary coll.pdf
f3apparelsonline
 
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdfThe force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
f3apparelsonline
 

More from f3apparelsonline (20)

How do the microsporangium and microspore in seed plants differ from.pdf
How do the microsporangium and microspore in seed plants differ from.pdfHow do the microsporangium and microspore in seed plants differ from.pdf
How do the microsporangium and microspore in seed plants differ from.pdf
 
Homework question with 2 partsA. Compare and contrast the geologic.pdf
Homework question with 2 partsA. Compare and contrast the geologic.pdfHomework question with 2 partsA. Compare and contrast the geologic.pdf
Homework question with 2 partsA. Compare and contrast the geologic.pdf
 
Client Business Risk The risk that the client will fail to achieve it.pdf
Client Business Risk The risk that the client will fail to achieve it.pdfClient Business Risk The risk that the client will fail to achieve it.pdf
Client Business Risk The risk that the client will fail to achieve it.pdf
 
Describe how removing water from a hydrophobic binding site or ligan.pdf
Describe how removing water from a hydrophobic binding site or ligan.pdfDescribe how removing water from a hydrophobic binding site or ligan.pdf
Describe how removing water from a hydrophobic binding site or ligan.pdf
 
create a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdfcreate a new interface called DropoutStackADT for representing a dro.pdf
create a new interface called DropoutStackADT for representing a dro.pdf
 
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdf
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdfCase Project 7-1 commen, diicrerne functions, arii price. wri.pdf
Case Project 7-1 commen, diicrerne functions, arii price. wri.pdf
 
Base your answer to questio n 25 on the map below and on your knowled.pdf
Base your answer to questio n 25 on the map below and on your knowled.pdfBase your answer to questio n 25 on the map below and on your knowled.pdf
Base your answer to questio n 25 on the map below and on your knowled.pdf
 
As presented, the tree summation algorithm was always illustrated wi.pdf
As presented, the tree summation algorithm was always illustrated wi.pdfAs presented, the tree summation algorithm was always illustrated wi.pdf
As presented, the tree summation algorithm was always illustrated wi.pdf
 
A person who quits a job in Los Angeles to look for work in Chicago i.pdf
A person who quits a job in Los Angeles to look for work in Chicago i.pdfA person who quits a job in Los Angeles to look for work in Chicago i.pdf
A person who quits a job in Los Angeles to look for work in Chicago i.pdf
 
4. Which one of the following is a key disadvantage of a a. As a gene.pdf
4. Which one of the following is a key disadvantage of a a. As a gene.pdf4. Which one of the following is a key disadvantage of a a. As a gene.pdf
4. Which one of the following is a key disadvantage of a a. As a gene.pdf
 
Who are the three agencies today that rate bondsHow do the three .pdf
Who are the three agencies today that rate bondsHow do the three .pdfWho are the three agencies today that rate bondsHow do the three .pdf
Who are the three agencies today that rate bondsHow do the three .pdf
 
Which of the following is trueChimpanzees and hominids share a comm.pdf
Which of the following is trueChimpanzees and hominids share a comm.pdfWhich of the following is trueChimpanzees and hominids share a comm.pdf
Which of the following is trueChimpanzees and hominids share a comm.pdf
 
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdfWhat does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
What does the multicellular Volvox and unicellular Chlamydomonas sug.pdf
 
What is the firm’s cost of preferred stock Please show work in Exce.pdf
What is the firm’s cost of preferred stock Please show work in Exce.pdfWhat is the firm’s cost of preferred stock Please show work in Exce.pdf
What is the firm’s cost of preferred stock Please show work in Exce.pdf
 
What are the 2 major cytoskeletal classes that participate in cell d.pdf
What are the 2 major cytoskeletal classes that participate in cell d.pdfWhat are the 2 major cytoskeletal classes that participate in cell d.pdf
What are the 2 major cytoskeletal classes that participate in cell d.pdf
 
Wanda is a 20 percent owner of Video Associates, which is treated as.pdf
Wanda is a 20 percent owner of Video Associates, which is treated as.pdfWanda is a 20 percent owner of Video Associates, which is treated as.pdf
Wanda is a 20 percent owner of Video Associates, which is treated as.pdf
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
 
To design an expert system, we must first identify a problem to be s.pdf
To design an expert system, we must first identify a problem to be s.pdfTo design an expert system, we must first identify a problem to be s.pdf
To design an expert system, we must first identify a problem to be s.pdf
 
Translate the following into English. Let C denote an arbitrary coll.pdf
Translate the following into English. Let C denote an arbitrary coll.pdfTranslate the following into English. Let C denote an arbitrary coll.pdf
Translate the following into English. Let C denote an arbitrary coll.pdf
 
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdfThe force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
The force on an object is F = - 21j. For the vector v = 2 i - 2j, fin.pdf
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

Use Java to program the following.1. Create public java class name.pdf

  • 1. Use Java to program the following. 1. Create public java class named Benford. 2. It's main function should prompt for the name of a data file and then the function iterates through the all of the elements in the data file and computes the frequency (count and percentage) of the first number in each entry. 3. Note: Some of the data files have comments that you must filter out. 4. Also note: that blank lines or lines where the number begins or is 0 must also be filtered out. 5. Your output must be formatted as follows. Solution Hi Firend, Please find my code. Please let me know in case of any issue. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CountFrequency { public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(System.in); // taking input file name System.out.print("Enter input file name: "); String fileName = sc.next(); // opening input file Scanner inputFile = new Scanner(new File(fileName)); // declaring array to store count of first digit of each entery int[] frequency = new int[10]; int totalCount = 0; // to maintain total count int num;
  • 2. // reading all lines while(inputFile.hasNextLine()){ // reading current line String line = inputFile.nextLine(); // if line is not empty if(line == null || line.isEmpty() || line.trim() == "") continue; // taking first character of current line char firstDigit = line.charAt(0); // if first character is digit and not equal to 0 if(Character.isDigit(firstDigit) && firstDigit != '0'){ // converting first character of current line in integer int d = firstDigit - '0'; frequency[d]++; totalCount++; } } System.out.println("DigittCounttFrequency"); for(int i=1; i<=9; i++){ System.out.println(i+"t"+frequency[i]+"t"+ ((double)frequency[i]/(double)totalCount*100)); } } } /* Sample run: ##### Entry of input.txt: 453 43 //543 123 0 4ee
  • 3. 875 52 // Output Enter input file name: input.txt Digit Count Frequency 1 1 20.0 2 0 0.0 3 0 0.0 4 2 40.0 5 1 20.0 6 0 0.0 7 0 0.0 8 1 20.0 9 0 0.0 */