import java.io.*;
import java.util.ArrayList;
public class Solution {
static ArrayList<Character> list = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1=reader.readLine();
String fileName2=reader.readLine();
reader.close();
//String fileName1="C:\\Users\\User\\Desktop\\TextExample.part1.txt";
//String fileName2="C:\\Users\\User\\Desktop\\TextExample.part2.txt";
BufferedReader myread = new BufferedReader(new FileReader(fileName1));
BufferedWriter mywrite = new BufferedWriter(new FileWriter(fileName2));
while (myread.ready())
{
list.add((char)myread.read());
}
int count=0;
String str="";
boolean flag=false;
//System.out.println (list.size());
for (int i=0; i<list.size(); i++){
char symbol=list.get(i);
//System.out.println(symbol);
if (Character.isDigit(symbol)){
if (i==0) {count++; flag=true; str=str.concat(Character.toString(symbol));}
else if (flag) {count++; str=str.concat(Character.toString(symbol));}
}
if (symbol==' '){
if (count>0){mywrite.write(str.concat(" ")); str=""; count=0; flag=true;}
else {flag=true; str="";}
}
if (!((Character.isDigit(symbol))||(symbol==' ')))
{
flag=false; str=""; count=0;
}
if((i==list.size()-1)&&(count>0))
{
mywrite.write(str.concat(" "));
}
}
myread.close();
mywrite.close();
}
}
package com.javarush.task.task19.task1908;
/*
Выделяем числа
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
static ArrayList<Character> list = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1=reader.readLine();
String fileName2=reader.readLine();
reader.close();
//String fileName1="C:\\Users\\User\\Desktop\\TextExample.part1.txt";
//String fileName2="C:\\Users\\User\\Desktop\\TextExample.part2.txt";
BufferedReader myread = new BufferedReader(new FileReader(fileName1));
BufferedWriter mywrite = new BufferedWriter(new FileWriter(fileName2));
while (myread.ready())
{
list.add((char)myread.read());
}
int count=0;
String str="";
boolean flag=false;
//System.out.println (list.size());
for (int i=0; i<list.size(); i++){
char symbol=list.get(i);
//System.out.println(symbol);
if (Character.isDigit(symbol)){
if (i==0) {count++; flag=true; str=str.concat(Character.toString(symbol));}
else if (flag) {count++; str=str.concat(Character.toString(symbol));}
}
if (symbol==' '){
if (count>0){mywrite.write(str.concat(" ")); str=""; count=0; flag=true;}
else {flag=true; str="";}
}
if (!((Character.isDigit(symbol))||(symbol==' ')))
{
flag=false; str=""; count=0;
}
if((i==list.size()-1)&&(count>0))
{
mywrite.write(str.concat(" "));
}
}
myread.close();
mywrite.close();
}
}