![]() |
|
Модераторы: Poseidon |
![]()
|
|
| WEST3940 |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 12 Регистрация: 27.2.2009 Репутация: нет Всего: нет |
Помогите с программой, чтоб результат записывался в текстовый файл .
import java.util.Scanner; import java.io.*; import java.util.ArrayList; import java.util.List; public class Main{ public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.println("vvedite stroku"); String str, g; String a = new String(); str = in.nextLine(); byte brasymas[]=new byte[1000]; brasymas=str.getBytes(); try{ FileOutputStream fileOut=new FileOutputStream("text1.txt"); fileOut.write(brasymas); } catch(Exception e){ System.out.println(e); } finally{ in.close(); String[] words = str.split("\\s*;\\s*"); if (words.length == 0) { System.err.println("No words found"); System.exit(1); } String firstWord = words[0]; Character centralChar = getCentralChar(firstWord); if (centralChar == null) { System.err.println("First word '" + firstWord + "' does not have central char"); System.exit(1); } char c = centralChar; List<String> result = new ArrayList<String>(); for (String word : words) { if (word.indexOf© != -1){ result.add(word); } } System.out.println("result = " + result); } } private static Character getCentralChar(String str) { if (str == null || str.length() == 0 || str.length() % 2 == 0) { return null; } return str.charAt(str.length() / 2); } } |
|||
|
||||
| LSD |
|
|||
![]() Leprechaun Software Developer ![]() ![]() ![]() ![]() Профиль Группа: Модератор Сообщений: 15719 Регистрация: 24.3.2004 Где: Dublin Репутация: 9 Всего: 538 |
Так у тебя и так уже результат частично выводится в файл.
-------------------- Disclaimer: this post contains explicit depictions of personal opinion. So, if it sounds sarcastic, don't take it seriously. If it sounds dangerous, do not try this at home or at all. And if it offends you, just don't read it. |
|||
|
||||
| WEST3940 |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 12 Регистрация: 27.2.2009 Репутация: нет Всего: нет |
Вот именно ,что выводиться только ввод с клавиатуры ,а результат выводиться не в файл ,а в консоль.
|
|||
|
||||
| LSD |
|
|||
![]() Leprechaun Software Developer ![]() ![]() ![]() ![]() Профиль Группа: Модератор Сообщений: 15719 Регистрация: 24.3.2004 Где: Dublin Репутация: 9 Всего: 538 |
-------------------- Disclaimer: this post contains explicit depictions of personal opinion. So, if it sounds sarcastic, don't take it seriously. If it sounds dangerous, do not try this at home or at all. And if it offends you, just don't read it. |
|||
|
||||
![]()
|
| Правила форума "Центр помощи" | |
|
|
ВНИМАНИЕ! Прежде чем создавать темы, или писать сообщения в данный раздел, ознакомьтесь, пожалуйста, с Правилами форума и конкретно этого раздела.
Более подробно с правилами данного раздела Вы можете ознакомится в этой теме. Если Вам помогли и атмосфера форума Вам понравилась, то заходите к нам чаще! С уважением, Poseidon, Rodman |
| 0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
| 0 Пользователей: | |
| « Предыдущая тема | Центр помощи | Следующая тема » |
|
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |