1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lianna [129]
3 years ago
7

g Create your own data file consisting of integer, double or String values. Create your own unique Java application to read all

data from the file echoing the data to standard output. After all data has been read, display how many data were read. For example, if 10 integers were read, the application should display all 10 integers and at the end of the output, print "10 data values were read" Demonstrate your code compiles and runs without issue. Respond to other student postings by enhancing their code to write the summary output to a file instead of standard output.
Computers and Technology
1 answer:
Jlenok [28]3 years ago
5 0

Answer:

See explaination

Explanation:

//ReadFile.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class ReadFile

{

public static void main(String[] args)

{

int elementsCount=0;

//Create a File class object

File file=null;

Scanner fileScanner=null;

String fileName="sample.txt";

try

{

//Create an instance of File class

file=new File(fileName);

//create a scanner class object

fileScanner=new Scanner(file);

//read file elements until end of file

while (fileScanner.hasNext())

{

double value=fileScanner.nextInt();

elementsCount++;

}

//print smallest value

System.out.println(elementsCount+" data values are read");

}

//Catch the exception if file not found

catch (FileNotFoundException e)

{

System.out.println("File Not Found");

}

}

}

Sample output:

sample.txt

10

20

30

40

50

output:

5 data values are read

You might be interested in
Where can i make a 3d animation for free ( pls don't trick me)
Vinvika [58]

Answer:

I don't know if it would work for what you need but you could try scratch. (sorry if this isn't what you needed.)

4 0
2 years ago
Bridge building is the business of: pure scientists, civil servants, or civil engineers?
LenKa [72]
Civil engineers is the correct business
6 0
3 years ago
Read 2 more answers
Write the interface (.h file) of a class Counter containing: A data member counter of type int. A data member named counterID of
OlgaM077 [116]

Explanation:

See the attached image for The interface (.h file) of a class Counter

8 0
3 years ago
Which statement accurately compares the restart at 1 and continue numbering featured of word
Andrews [41]

Answer: the continue numbering feature can be used to maintain the numbering order in a list and the restart at 1 feature can be used to make a new list

Explanation:

7 0
3 years ago
Read 2 more answers
What provision of the Government Paperwork Elimination Act was designed to encourage a paperless society?
Ratling [72]
<span>Validation of electronic signatures was designed to encourage a paperless society.</span>
8 0
3 years ago
Read 2 more answers
Other questions:
  • Parameter variables should not be changed within the body of a method because _______________. Select one: a. it mixes the conce
    5·1 answer
  • What are two major techniques involved in green computing
    14·1 answer
  • What is an avenue in a Karel world?
    6·2 answers
  • How many pounds must a sand bag weigh to test if a safety net can absorb the proper amount of force? A. 150 lbs. B. 200 lbs. C.
    6·1 answer
  • What is wrong with this code and correct it.
    12·1 answer
  • Which of the following is a property of TCP?
    8·1 answer
  • Please answer this question​
    8·1 answer
  • Explain the measures put in place in order to maintain each of the element of computer security<br>​
    10·1 answer
  • The people, procedures, hardware, software, data, and knowledge needed to develop computer systems and machines that can simulat
    13·1 answer
  • Aisha designed a web site for her school FBLA club and tested it to see how well it would resize on different systems and device
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!