RandomNotryBubbles

RandomNotryBubbles - System.out.println"largest...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.io.*; // Import all classes in java.io package. Saves typing. // the BufferedReaderClass we will use for keyboard // input is in this package public class RandomNotryBubbles { p public static void main(String[] args){ String line; // to hold user keyboard input double num = 0; // to hold the integer converted from the the user input int i; int MAX; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); MAX = Integer.parseInt(args[0]); if (MAX <= 0) { System.out.println("Must give a positive integer"); return; } Random gen = new Random(); double ranNum; double[] numbers; numbers = new double[MAX]; // double[] numbers = new double[MAX]; System.out.println("generating random numbers to sort"); for (i=0; i<numbers.length; i++) { ranNum = 100*gen.nextDouble();//between 0 and 1000 System.out.println("number: "+ranNum); numbers[i] = ranNum; }// end for System.out.print("original numbers: "); printValues(numbers); System.out.println();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println("largest value: "+ getLargest(numbers)); System.out.print("one bubble numbers: "); bubbleUpBiggest(numbers); printValues(numbers); System.out.println(); System.out.print("bubble sorted numbers: "); bubbleSort(numbers); printValues(numbers); System.out.println(); }// end main method public static void printValues (double arr) { int i; for (i=0; i<arr.length; i++) { System.out.print(arr[i]+", "); } return; } public static double getLargest (double arr) { int i; double big = 0; for (i=0; i<arr.length; i++) { if (arr[i]>big) { big = arr[i]; } } return big; } public static void bubbleUpBiggest (double arr) { int i; double temp; for (i=0; i<arr.length-1; i++) { if (arr[i] > arr[i+1]) { temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } } return; } public static void bubbleSort (double arr) { int i; for (i=0; i<arr.length; i++) { bubbleUpBiggest(arr); } return; } } // end class...
View Full Document

This note was uploaded on 11/30/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 2

RandomNotryBubbles - System.out.println"largest...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online