My test case include
1n n1 1n1 n1n abc1 adsa%4125
a1 abc3d @#$!%@%1 fasgqqr
package com.codegym.task.task19.task1923;
/*
Words with numbers
The main method's first parameter is file1 and the second is file2.
file1 contains lines with words separated by spaces.
Write to file2 all the words that contain numbers, for example, a1 or abc3d. Separate the words with spaces.
Close the streams.
*/
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Solution {
public static void main(String[] args) throws IOException {
FileReader f1 = new FileReader(args[0]);
FileWriter f2 = new FileWriter(args[1]);
while (f1.ready()) {
StringBuilder sbr = new StringBuilder();
char cur;
boolean ifAdd = false;
while (f1.ready() && (cur = (char) f1.read()) != ' ') {
if (cur >= '0' && cur <= '9') {
ifAdd = true;
}
sbr.append(cur);
}
if (ifAdd) {
f2.write(sbr.toString() + " ");
}
}
f1.close();
f2.close();
}
}