Created
November 26, 2016 14:47
-
-
Save alekseytimoshchenko/961861276fa0c5f6be771ead79be6b14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedReader reader = new BufferedReader(new FileReader(br.readLine())); | |
BufferedWriter writer = new BufferedWriter(new FileWriter(br.readLine(), true)); | |
String[] str; | |
String line; | |
while ((line = reader.readLine()) != null){ | |
str = line.split(" "); | |
for (String tmp : str){ | |
if (isNumeric(tmp)){ | |
String strToWrite = tmp + " "; | |
writer.write(strToWrite); | |
} | |
} | |
} | |
br.close(); | |
reader.close(); | |
writer.close(); | |
} | |
public static boolean isNumeric(String str) | |
{ | |
try | |
{ | |
double d = Double.parseDouble(str); | |
} | |
catch(NumberFormatException nfe) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment