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

Thread: Java error in using Arrays

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java error in using Arrays

    Hi all,
    I have to w.a.p to display name,age and designation using an array.I am bit confused with arrays any have i tried and written a code,but its showing an error.
    [COLOR="Blue"]class Array
    { 
    public static void main(String args[]) 
    {
    int S[]={{dfg,20,manager},{fgh,36,Asst.Manager},{fgh,36,Marketing Manager}};
    for(int i=0;i<3;i++)
    System.out.println(s[i]);
    }
    }[/COLOR]

    This is the code i have written,will u plz rectify the mistakes.
    Thank u.


  2. #2
    Junior Member
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    Still far, far away from practical

     
    String[] s = new String[3];
     
    s[0] = "dfg, 20, manager";
    s[1] = "fgh, 36, AsstManager";
    s[2] = "fgh, 36, Marketing Manager";
     
    for(int i=0;i<3;i++)
    {
        System.out.println(s[i]);
    }

    I'm just starting out Java myself so be kind :p

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Arrays

    Hello AnithaBabu1.

    There is actually quite a few things wrong with your code. For starters, you are trying to hold String values in an Int variable.
    Your for loop looks fine so its just Arrays you need to look at.

    d3mian has posted a good example. This will work perfectly. As you see the array type is a String variable and this is the easiest way to code it.

    Welcome to the Java Programming Forums d3mian!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    Thank u so much,it works!!!

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Arrays

    Quote Originally Posted by AnithaBabu1 View Post
    Thank u so much,it works!!!
    I'm glad you found your answer here AnithaBabu1.

    For a more information check the official Sun Java Tutorials:

    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Elegant and short way to implement my program on 2d Array
    By TheForumLord in forum Collections and Generics
    Replies: 1
    Last Post: December 8th, 2008, 03:56 PM