Created
February 17, 2014 18:29
-
-
Save slava-konashkov/9056234 to your computer and use it in GitHub Desktop.
Ввести массив с консоли и отсортировать его
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test; | |
| import java.io.BufferedReader; | |
| import java.util.*; | |
| import java.io.*; | |
| public class MyArr { | |
| 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 { | |
| Arrays.sort(iaMain); | |
| 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