NotryBubbles

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 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 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(System.in)); 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(&quot;one bubble numbers: &quot;); bubbleUpBiggest(numbers); printValues(numbers); System.out.println(); System.out.print(&quot;bubble sorted numbers: &quot;); bubbleSort(numbers); printValues(numbers); System.out.println(); }// end main method public static void printValues (double arr) { int i; for (i=0; i&lt;arr.length; i++) { System.out.print(arr[i]+&quot;, &quot;); } return; } public static double getLargest (double arr) { int i; double big = 0; for (i=0; i&lt;arr.length; i++) { if (arr[i]&gt;big) { big = arr[i]; } } return big; } public static void bubbleUpBiggest (double arr) { int i; double temp; for (i=0; i&lt;arr.length-1; i++) { if (arr[i] &gt; 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&lt;arr.length; i++) { bubbleUpBiggest(arr); } return; } } // end class...
View Full Document

Page1 / 2

NotryBubbles - System.out.print(&amp;amp;quot;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