Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SortIntegers.java
- //Jonathan Sell
- import java.io.*;
- import java.util.Scanner;
- import utilities.Arrays;
- public class SortIntegers
- {
- // interactively reads in any list of integers ( maximum of 100), one per line
- // prints out the original list ( before it is sorted and the sorted list
- public static void main(String[] args)throws IOException
- {
- Integer[] number = new Integer[ 100 ];
- System.out.println("type in up to 100 integers, one per line - enter an empty line to stop");
- int size = readArray(number);
- System.out.println("The original list: ");
- printArray(number, size);
- Arrays.selectionSort(number);
- System.out.println("The sorted list:");
- printArray(number, size);
- }
- // interactively reads in list of integers (max 100) into an array
- //returns number of integers stored
- public static int readArray(Integer[] number) throws IOException
- {
- Scanner scanner = new Scanner(System.in);
- String line = null;
- int count = 0;
- while( true )
- {
- line = scanner.nextLine();
- if(line.equals(""))
- break;
- number[count] = new Integer(line);
- }
- return count;
- }
- //prints out array
- public static void printArray(Integer[] number, int size)
- {
- int count = 0;
- while (count <= 0)
- {
- System.out.println(number[count]);
- count++;
- }
- }
- }
Add Comment
Please, Sign In to add comment