Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- public class Main {
- public static void main(String[] args) {
- try (FileInputStream x = new FileInputStream("1.txt")) {
- byte[] buf = new byte[x.available()];
- String s = "", b = "";
- x.read(buf, 0, x.available());
- for (int i = 0; i < buf.length; i++) {
- s += (char)buf[i];
- }
- s += " ";
- System.out.println("Первоначальная строка: " + s);
- System.out.print("Новая строка: ");
- for (int i = 0; i < s.length() - 1; i++) {
- int k = 1;
- while (i < s.length() - 1 && s.charAt(i) == s.charAt(i+1)) {
- k += 1;
- i += 1;
- }
- b += s.charAt(i) + String.valueOf(k);
- }
- System.out.print(b);
- if (x != null) x.close();
- } catch(IOException ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment