NotryBubbles - System.out.print"one bubble...

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

View Full Document Right Arrow Icon
import*; // Import all classes in package. Saves typing. // the BufferedReaderClass we will use for keyboard // input is in this package public class NotryBubbles { p public static void main(String[] args) throws IOException { 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(; MAX = Integer.parseInt(args[0]); if (MAX <= 0) { System.out.println("Must give a positive integer"); return; } double[] numbers; numbers = new double[MAX]; // double[] numbers = new double[MAX]; for (i=0; i<numbers.length; i++) { System.out.print("number? "); line = in.readLine(); numbers[i] = Double.parseDouble(line); }// end for System.out.print("original numbers: "); printValues(numbers); System.out.println(); System.out.println("largest value: "+ getLargest(numbers));
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.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

NotryBubbles - System.out.print"one bubble...

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