Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Help with java insertion sort program Date: Sun, 10 Aug 2014 05:54:25 -0400 Organization: A noiseless patient Spider Lines: 73 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 10 Aug 2014 09:54:49 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="4860"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gwC6wTZsRNYNAkEshZ8yka2yNwYJx3gM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 In-Reply-To: Cancel-Lock: sha1:U6qxWbszwmw6pQoAMkenqxZTWMg= Xref: csiph.com comp.lang.java.programmer:29614 On 08/10/2014 12:30 AM, Jeff Higgins wrote: > On 08/10/2014 12:11 AM, Scott Dunning wrote: >> Ok so I realized that I was not filling the array with anything but now >> I'm having issues filling it correctly. It's only filling the array >> with three of the user inputs and I just cannot figure out why.... > > I thought you had that sorted over at stackoverflow. > I must have misread that too. > > Please, PLEASE, use java.io.Console class. It makes joy. > If your Professor disallows it, understand him as saying: > "F**k me runnin'." > Huh, some Java IDEs understand Console the same way! School begins Monday for our local grade-schoolers, are you sure you're in a summer class? import javax.swing.JOptionPane; public class DriverSort { public static void main(String[] args) { Object[] sorts = {"Insertion", "Selection", "Bubble"}; String sortString = (String)JOptionPane.showInputDialog( null, "Select a sort algorithm\nCancel quits the program", "Sort Algorithm Selector", JOptionPane.PLAIN_MESSAGE, null,sorts,"Insertion"); if(sortString == null) { System.exit(1); } else if(sortString != "Insertion"){ JOptionPane.showMessageDialog( null, "Selection and Bubble sorts are not implemented"); System.exit(2); } String arrayString = (String)JOptionPane.showInputDialog( null, "Enter a space separated list of integers\nCancel quits the program", "The Array to Sort" ,JOptionPane.PLAIN_MESSAGE,null,null,""); if(arrayString == null) { System.exit(3); } try { String[] stringArray = arrayString.split(" "); int[] input = new int[stringArray.length]; for (int i = 0; i < stringArray.length; i++) { input[i] = Integer.parseInt(stringArray[i]); } Sorter.insertionSort(input); Sorter.printArray(input); } catch (NumberFormatException e) { JOptionPane.showMessageDialog( null, "Could not parse a list of integers"); System.exit(4); } } }