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 4 of 4

Thread: Array

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array

    import java.util.Scanner;

    public class Lab10_Ex3
    {

    public static void main (String [] args)
    {

    String [] strings = new String[4];

    strings[0] = "Einstein";
    strings[1] = "Newton";
    strings[2] = "Copernicus";
    strings[3] = "Kepler";

    showElements(strings);


    }
    public static void showElements(int[] strings)
    {
    System.out.print("The contents of the array are: ");
    System.out.println(strings[0]);
    System.out.println(strings[1]);
    System.out.println(strings[2]);
    System.out.println(strings[3]);



    }
    }

    ERROR:

    showElements(int[]) in Lab10_Ex3 cannot be applied to (java.lang.String[])
    showElements(strings);
    ^
    1 error


    any ideas?


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Array

    Look at what the error is telling you. You are putting a String[] as an argument to a method that requires an int[]:

    public static void showElements(int[] strings)

    If you want the method to take a String[] as input, you have to declare it as such.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array

    rookie mistake......but then again, I am a rookie!!

    Thx!

  4. #4
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Array

    Glad you got it working!

    Have fun learning the language!
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. Array List of Array Lists working for first item but not for second.
    By javapenguin in forum Collections and Generics
    Replies: 6
    Last Post: February 15th, 2012, 04:12 PM
  2. Replies: 4
    Last Post: November 14th, 2011, 09:00 PM
  3. Doubling The Array Size And Randomizing Array Return
    By Pingu00 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 27th, 2011, 10:50 AM
  4. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  5. Replies: 2
    Last Post: May 6th, 2011, 05:19 PM