Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Writing a method that returns words without four letters back to main method!

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    5
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Writing a method that returns words without four letters back to main method!

    Hi, so I need help with this program. I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy. Any thoughts? Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck. Thank you very much in advance.

     
    import java.util.Scanner;
     
    public class censorProgram {
      public static void main (String args[]){  
     
        Scanner input = new Scanner (System.in);     
        System.out.println ("How many words would you like to enter?");         
        int lineOfText = input.nextInt();  
     
        System.out.println ("Enter your words.");         
        String [] words = new String [lineOfText];  
     
        for (int i = 0; i < words.length; i ++){
          words[i] = input.next();     
     
     
        }
        System.out.println (words); 
      }
    }
     
     // prints [Ljava.lang.String;@38cfdf 
     //have to make new string array in the method and return words without four letters in the main method


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Writing a method that returns words without four letters back to main method!

    my code so far just prints [Ljava.lang.String;@38cfdf
    That is the String returned by the array's toString() method. For debugging use the Arrays class's toString() method to format an array for printing:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Location
    Chennai
    Posts
    9
    My Mood
    Cool
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Writing a method that returns words without four letters back to main method!

    Hello. you are almost done. The only thing you have to do is check for the logic and print the array.

Similar Threads

  1. Method returns empty stack when called
    By pyler in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 7th, 2013, 05:46 PM
  2. Replies: 12
    Last Post: March 17th, 2013, 01:38 AM
  3. method always returns 0
    By bdennin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 26th, 2013, 05:31 AM
  4. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  5. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM