Working on a bin sort; user enters a bunch of number and then I sort them.
I keep getting the error "cannot find symbol" and an arrow pointing to the period in mbin.elementAt(i) and ever time I have an arrayList command in my method. What's going on, can the method not access the arrayList created in the main? Help.
//CS 108 import java.util.*; public class HW4 { public static ArrayList<String> mbin = new ArrayList<String>(); public static ArrayList[] sbins = new ArrayList[10]; public static void main(String args[]) { for (int i=0; i<=9; i++) //create each of the sort bins, 0 through 9 { sbins[i] = new ArrayList(); } Scanner input = new Scanner(System.in); String numIn = null; System.out.println("Input a value from 0 to 9999. When done inputting hit the ENTER key alone."); while((numIn = input.nextLine( )).length( ) > 0) { if(numIn.length( ) > 4) { System.out.println("The number you entered is too big. Input a value from 0 to 9999."); } else { System.out.println("Input a value from 0 to 9999 if done inputting hit the ENTER key alone."); mbin.add(numIn); } } System.out.print("You entered: "); System.out.println( mbin.toString() ); MtoS(3); StoM(); MtoS(2); StoM(); MtoS(1); StoM(); MtoS(0); StoM(); System.out.println( mbin.toString() ); } public static void MtoS(int p) { for(int i = 0; i < (mbin.size() - 1); i++) { String s = mbin.elementAt(i); char c = ' '; if(s.length( ) == 4) { c = s.charAt(p); } else if(s.length( ) == 3) { c = s.charAt(p-1); } else if(s.length( ) == 2) { c = s.charAt(p-2); } else { c = s.charAt(p-3); } if(c == '9') { sbins[9].addElement(s); } else if(c == '8') { sbins[8].addElement(s); } else if(c == '7') { sbins[7].addElement(s); } else if(c == '6') { sbins[6].addElement(s); } else if(c == '5') { sbins[5].addElement(s); } else if(c == '4') { sbins[4].addElement(s); } else if(c == '3') { sbins[3].addElement(s); } else if(c == '2') { sbins[2].addElement(s); } else if(c == '1') { sbins[1].addElement(s); } else { sbins[0].addElement(s); } } } public static void StoM() { for(int i = 0; i < (sbins[9].size() - 1); i++) { String s = sbins[9].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[8].size() - 1); i++) { String s = sbins[8].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[7].size() - 1); i++) { String s = sbins[7].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[6].size() - 1); i++) { String s = sbins[6].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[5].size() - 1); i++) { String s = sbins[5].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[4].size() - 1); i++) { String s = sbins[4].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[3].size() - 1); i++) { String s = sbins[3].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[2].size() - 1); i++) { String s = sbins[2].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[1].size() - 1); i++) { String s = sbins[1].elementAt(i); mbin.addElement(s); } for(int i = 0; i < (sbins[0].size() - 1); i++) { String s = sbins[0].elementAt(i); mbin.addElement(s); } } }