fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11.  
  12. System.out.println("Input up to '10' numbers for current array: ");
  13.  
  14. int[] array1 = new int[10];
  15. int i;
  16.  
  17. Scanner scan = new Scanner(System.in);
  18.  
  19. for (i = 0; i < 10; i++) {
  20. System.out.println("Input a number for " + (i + 1) + ": ");
  21. int input = scan.nextInt();
  22. if (input == -9000) {
  23. break;
  24. } else {
  25. array1[i] = input;
  26. }
  27. }
  28.  
  29. System.out.println("\n" + "Original Array: ");
  30.  
  31. for (int j = 0; j < i; j++) {
  32.  
  33. System.out.println((j + 1) + ": " + array1[j]);
  34. }
  35.  
  36. System.out.println("\n" + "Organized Array: ");
  37.  
  38. int[] array2 = new int[i];
  39. for (int j = 0; j < i; j++) {
  40. array2[j] = array1[j];
  41. }
  42. for (int j = 0; j < i; j++) {
  43. int temp;
  44. boolean numerical = false;
  45.  
  46. while (numerical == false) {
  47. numerical = true;
  48.  
  49. for (int m = 0 ; m < array2.length - 1; m++) {
  50. if (array2[m] > array2[m + 1]) {
  51. temp = array2[m + 1];
  52. array2[m + 1] = array2[m];
  53. array2[m] = temp;
  54. numerical = false;
  55. }
  56. }
  57. }
  58. }
  59. for (i = 0; i < array2.length; i++) {
  60. System.out.println(array2[i]);
  61. }
  62. }
  63.  
  64. }
Success #stdin #stdout 0.13s 321088KB
stdin
100 200 50 76 11 -9000
stdout
Input up to '10' numbers for current array: 
Input a number for 1: 
Input a number for 2: 
Input a number for 3: 
Input a number for 4: 
Input a number for 5: 
Input a number for 6: 

Original Array: 
1: 100
2: 200
3: 50
4: 76
5: 11

Organized Array: 
11
50
76
100
200