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

Thread: I want to store names and marks in an array. I am confused what should be the code

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want to store names and marks in an array. I am confused what should be the code

    import java.util.Scanner;

    public class InputArray
    {
    public static void main(String[]args)
    {
    String name = "";
    {
    Scanner ScanObj = new Scanner(System.in);

    for(int i = 1 ; i < 6 ; i ++)
    {
    System.out.println("Enter a name: ");
    name = ScanObj.next();
    }

    String temp += name;
    System.out.println("The names you entered are:" + name);
    }
    }


    }


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: I want to store names and marks in an array. I am confused what should be the cod

    Read: Arrays
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to store names and marks in an array. I am confused what should be the cod

    Quote Originally Posted by newbie View Post
    Read: Arrays
    I dont want to hard code it. I know that you can have 2 arrays, one of string type to store names and the other of int type for the marks and then you can display them using the index of the element of any particular array.

    However I want the array to ne dynamic and it should be filled by the user and not hard coded. What is the best way to go about it. I want to use arrays and not array lists.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I want to store names and marks in an array. I am confused what should be the cod

    To assign a value to an element in an array you code something like this:
    anArray[ix] = theValue; // set the element at ix to theValue

    Then vary the value of ix to move from one element to the next.

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want to store names and marks in an array. I am confused what should be the cod

    You could use ArrayList?

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I think you can make object array.
    Each object saved in the array has two values which are name and mark.
    Can you make one more class?

Similar Threads

  1. Array problems...newby...confused?
    By toppcon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 9th, 2011, 03:10 AM
  2. array to store multiple names and data
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 05:03 AM
  3. How to store objects from a class inn an array?
    By dironic88 in forum Object Oriented Programming
    Replies: 1
    Last Post: April 7th, 2011, 02:42 PM
  4. Issue with code. Does not detect duplicate names in file
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2011, 01:13 AM
  5. Store Values in 2D array and output to textarea
    By raverz1tildawn in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2011, 03:13 PM