public class Solution {
public static byte[] sortArray(byte[] array){
if (array[(array.length) - 1] % 2 != 0) {
return array;
} else {
for (int i = 0; i < (array.length)-1; i+=2) {
byte temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
return array;
}
}
public static void main(String[] args) {
//напишите тут ваш код
String fileOne = null;
String secondFile = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
fileOne = reader.readLine();
secondFile = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
byte[] buffer = null;
try(FileInputStream inputStream = new FileInputStream(fileOne); FileOutputStream fileOutputStream =
new FileOutputStream(secondFile)){
buffer = new byte[6456];
inputStream.read(buffer);
sortArray(buffer);
fileOutputStream.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.javarush.task.pro.task15.task1524;
import java.io.*;
/*
Перепутанные байты
*/
public class Solution {
public static byte[] sortArray(byte[] array){
if (array[(array.length) - 1] % 2 != 0) {
return array;
} else {
for (int i = 0; i < (array.length)-1; i+=2) {
byte temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
return array;
}
}
public static void main(String[] args) {
//напишите тут ваш код
String fileOne = null;
String secondFile = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
fileOne = reader.readLine();
secondFile = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
byte[] buffer = null;
try(FileInputStream inputStream = new FileInputStream(fileOne); FileOutputStream fileOutputStream =
new FileOutputStream(secondFile)){
buffer = new byte[6456];
inputStream.read(buffer);
sortArray(buffer);
fileOutputStream.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}