Skip to content

Instantly share code, notes, and snippets.

@slava-konashkov
Created February 17, 2014 18:57
Show Gist options
  • Select an option

  • Save slava-konashkov/9056710 to your computer and use it in GitHub Desktop.

Select an option

Save slava-konashkov/9056710 to your computer and use it in GitHub Desktop.
Зеркальное отображение массива
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class ArraySplit {
public static void main(String[] args) throws Exception {
int[] iaMain = null;
int[] iaTmp;
BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
String sIn;
int iTmp;
while (true) {
try {
System.out.println("Введите число:");
sIn = d.readLine();
iTmp = Integer.parseInt(sIn);
if (null == iaMain) {
iaMain = new int[]{iTmp};
} else {
iaTmp = new int[iaMain.length+1];
System.arraycopy(iaMain, 0, iaTmp, 0, iaMain.length);
iaTmp[iaMain.length] = iTmp;
iaMain = iaTmp;
}
} catch (Exception e) {
System.out.println("Ввод закончен.");
break;
}
}
try {
for(int i = 0; i < iaMain.length>>1; i++) {
iTmp = iaMain[iaMain.length-i-1];
iaMain[iaMain.length-i-1] = iaMain[i];
iaMain[i] = iTmp;
}
System.out.println(Arrays.toString(iaMain));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment