-1

My program declares two character arrays of size 26(char [26]), randomly takes letters from a string containing a-z and A-Z, and the uses them to populate both arrays. Lastly, it takes every lowercase letter from both arrays, and then uses them to populate an ArrayList, which is sorted in alphabetical order, and then displayed(or at least that's what it's supposed to do). I'm not entirely sure what the issue is, much less how to fix it, so any assistance would be appreciated.

package HW_5;
import java.util.Random;
import java.util.Arrays;
import java.util.ArrayList;

public class HW_5
{
    static char [] first = new char [26];
    static char [] second = new char [26];
    static String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static Random r = new Random();
    static char letter = ' ';

    public static void main(String[] args)
    {
        Character [] third;
        Random_Alphabetic_Generator();
        third = Lowercase_Container();
        Alphabetical_Order(third);


    }

    public static void Random_Alphabetic_Generator()
    {


            for(int i=0; i < first.length; i++)
            {

                letter = alphabet.charAt((int) r.nextInt(alphabet.length()));
                first[i] = letter;
            }
            for(int i=0; i < second.length; i++)
            {
                letter = alphabet.charAt((int) r.nextInt(alphabet.length()));
                second[i] = letter;
            }


            System.out.println("First Array Contains: " + Arrays.toString(first));
            System.out.println("Second Array Contains: " + Arrays.toString(second));
    }

    public static Character [] Lowercase_Container()
    {

         ArrayList<Character> container = new ArrayList<Character>();

         for(int i = 0; i < first.length; i++)
         {
             if(first[i] == Character.toLowerCase(first[i]))
             {
                container.add(first[i]);
             }
         }
         for(int i = 0; i < second.length; i++)
         {
             if(second[i] == Character.toLowerCase(second[i]))
             {
                container.add(second[i]);
             }   
         }

         Character [] third = new Character[container.size()];
         container.toArray(third);


         return third;
    }

    public static void Alphabetical_Order(Character [] third)
    {
        java.util.Arrays.sort(third);
        System.out.println("All lowercase letters from the First and Second Arrays: " + third);
    }

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    [Search for similar questions before posting](https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1LEND_enUS445US445&ion=1&espv=2&ie=UTF-8#q=java+array+is+displaying+memory+location+site:http:%2F%2Fstackoverflow.com%2F). – Hovercraft Full Of Eels Oct 19 '15 at 04:15

1 Answers1

0

You needs to use Arrays.toString like:

 System.out.println("All lowercase letters from the First and Second Arrays: " + Arrays.toString(third));
akhil_mittal
  • 23,309
  • 7
  • 96
  • 95