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
rusak2 [61]
4 years ago
13

Create your own unique Java application to read all data from the file echoing the data to standard output. After all data has b

een 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"
Computers and Technology
1 answer:
mafiozo [28]4 years ago
8 0

Answer:

<u>Output</u>

The values read are:  

25

3

4

65

7

9

5

6

1

11

10 data values were read

Explanation:

Below is the Java program to read all data from the file echoing the data to standard output and finally displaying how many data were read:-

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class MyFileReader {

public static void main(String[] args){

 int num,counter=0;

 File file=new File("numbers.txt");

 try {

  Scanner input=new Scanner(file);

  System.out.println("The values read are: ");

  while(input.hasNext()){

   num=input.nextInt();

   System.out.println(num);

   counter+=1;

  }

  System.out.println(counter+" data values were read");

 } catch (FileNotFoundException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

 }

}

}

You might be interested in
Identify the following verb by number and person by checking on the appropriate boxes.
Makovka662 [10]
Second person ig Imao yeah
3 0
3 years ago
Read 2 more answers
Answering a questi
irina1246 [14]

Answer:

character

Which word (s) best describe personality. character

4 0
3 years ago
To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: 1. Create a list of consecutive i
natta225 [31]

Answer:

I am writing a Python program:

def Eratosthenes(n):  

   primeNo = [True for i in range(n+1)]  # this is a boolean array

   p = 2  # the first prime number is initialized as 2

   while (p * p <= n):     # enumerates all multiples of p

       if (primeNo[p] == True):                

           for i in range(p * p, n+1, p):  #update multiples

               primeNo[i] = False

       p = p + 1        

   for p in range(2, n):   #display all the prime numbers

       if primeNo[p]:  

           print(p),    

def main():     #to take value of n from user and display prime numbers #less than or equal to n by calling Eratosthenes method

   n= int(input("Enter an integer n: "))

   print("The prime numbers less than or equal to",n, "are: ")  

   Eratosthenes(n)      

main()      

Explanation:

The program contains a Boolean type array primeNo that is initialized by True which means that any value i in prime array will be true if i is a prime otherwise it will be false. The while loop keeps enumerating all multiples of p starting from 2, and striking them off from the original array list and for loops keep updating the multiples. This process will continue till the p is greater than n.  The last for loop displays all the prime numbers less than or equal to n which is input by user. main() function prompts user to enter the value of integer n and then calls Eratosthenes() function to print all the prime numbers less than or equal to a given integer n.

   

7 0
3 years ago
What is an optical drive used for?​
solong [7]

Optical Disc Drive (ODD) An optical disc drive (ODD)

for using CDs, DVDs, and Blu-ray discs to listen to music or watch a movie.

Most drives also allow you to write data to a disc, so you can create your own music CDs, video DVDs or even create of back-up copy of your important data files.

dell.com

4 0
2 years ago
Read 2 more answers
What is an active cooling solution for a PC?
mina [271]
Reduce the speed of the CPU
6 0
3 years ago
Read 2 more answers
Other questions:
  • Can your computer become infected with a virus via email
    6·1 answer
  • .When an argument is passed ______________, the called method can access and modify the caller’s original data directly.
    8·1 answer
  • Application partitioning gives developers the opportunity to write application code that can later be placed on either a client
    7·1 answer
  • It is essential for a relay energized by alternating current to have
    13·1 answer
  • What are two reasons for converting a document or record into a digitized format?
    6·1 answer
  • Explain the four misconceptions about entrepreneurship.
    7·1 answer
  • How are computers connected to one another?
    5·2 answers
  • What are software applications?
    14·1 answer
  • A constraint that is concerned with cost and must be considered when designing is Group of answer choices Economic Aesthetic Pol
    6·1 answer
  • The local Driver's License Office has asked you to write
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!