• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with reading integers from a file  RSS feed

 
ab kwawme
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WRITE A JAVA PROGRAM THAT READS INTEGERS ONLY FROM A TEXT FILE "myData.txt",
sqaure the integers and then send the result to an output file "myoutput.txt".
The program should be able to skip text characters in the file and square only inegers
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

We don't give complete solutions but we will help you if you show some effort. Please post the code you have written so far and explain where you are stuck and we will help you.
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes, you're right, I have inspiration and write a decision without explanation.
For the example, I can say:
0. Of course, we need to read file and make analysis of all the lines.
1. When we are reading a *.txt file we do it line by line and check all numbers in line. At first, we divide read line using method split() and save the words in the array.
2. Having array of words, using regexp for digit numbers, we use it like a template for each word in the read line;
3. If words appropriate to the regexp we execute math operation and add it to the general list of the numbers: foundInt()
4. Now, we can save our list to the output file.
 
Norm Radder
Rancher
Posts: 2240
28
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!