Pagini recente » Cod sursa (job #2525848) | Cod sursa (job #2605320) | Cod sursa (job #505733) | Cod sursa (job #2244772) | Cod sursa (job #1939872)
import java.io.*;
public class Main {
public static void main(String ...args) {
String text;
int totalLetters = 0;
int totalWords = 0;
try(BufferedReader reader = new BufferedReader(new FileReader("text.in"))) {
while(reader.read() != -1) {
text = reader.readLine();
for(int i = 0; i < text.length(); i++) {
int wordCheck = 0;
while((text.charAt(i) >= 'a' && text.charAt(i) <= 'z') || (text.charAt(i) >= 'A' && text.charAt(i) <= 'Z')) {
i++;
totalLetters++;
wordCheck = 1;
}
totalWords += wordCheck;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try(BufferedWriter writer = new BufferedWriter(new FileWriter("text.out"))) {
writer.write(String.valueOf(totalWords != 0 ? totalLetters/totalWords : 0));
} catch (IOException e) {
e.printStackTrace();
}
}
}