Você está na página 1de 3

import java.util.*; import java.io.

*; class ReadFile { //FIELDS static int cnt = 0; static int data[] ; static FileReader fr = null ; static Scanner sc = null ; static Scanner sTmp = new Scanner(System.in); //METHODS public static void main(String[] args) throws Exception { fr = new FileReader("input.txt"); sc = new Scanner( fr ); while( sc.hasNext()) { sc.next() ; cnt++ ; } data fr = sc = for( { } displayArray() ; highestValue() ; lowestValue() ; displayOdd() ; displayEven() ; sortAscending() ; sortDescending() ; } static void displayArray() { System.out.println("ARRAY CONTENT"); for( int x=0; x<data.length; x++) { System.out.println("Array["+ x +"]:\t" + data[x]); interrupt(x) ; } } static void interrupt(int c ) { if(c%50 == 0) { System.out.println("Press [ENTER] to continue..."); sTmp.nextLine(); } } = new int[cnt]; new FileReader("input.txt"); new Scanner( fr ); int x=0; x<data.length; x++) data[x] = sc.nextInt() ;

static void displayOdd() { System.out.println("\nODD NUMBERS") ; for( int x=0; x<data.length; x++) { if( data[x]%2 != 0 ) { System.out.println("ARRAY[" + x + "]\t" + data[x]) ; interrupt(x) ; } } } static void displayEven() { System.out.println("\nEVEN NUMBERS") ; for( int x=0; x<data.length; x++) { if( data[x]%2 == 0 ) { System.out.println("ARRAY[" + x + "]\t" + data[x]) ; interrupt(x) ; } } } static void sortAscending() { System.out.println("\nSORT ASCENDING") ; for( int x=0; x<data.length-1; x++) { for( int y=0; y<data.length-1; y++) { if (data[y] > data[y+1] ) { int tmp = data[y] ; data[y] = data[y+1] ; data[y+1] = tmp ; } } } displayArray() ; } static void sortDescending() { System.out.println("\nSORT DESCENDING") ; for( int x=0; x<data.length-1; x++) { for( int y=0; y<data.length-1; y++) { if (data[y] < data[y+1] )

{ int tmp = data[y] ; data[y] = data[y+1] ; data[y+1] = tmp ; } } } displayArray() ; }

static void highestValue() { int high = Integer.MIN_VALUE ; for( int x=0; x<data.length; x++) { if( high<data[x] ) { high = data[x] ; } } System.out.println( "\n\nThe highest array value is:\t" + high ) ; } static void lowestValue() { int low = Integer.MAX_VALUE ; for( int x=0; x<data.length; x++) { if( low>data[x] ) { low = data[x] ; } } System.out.println( "\n\nThe lowest array value is:\t" + low ) ; } }

Você também pode gostar