Results 1 to 3 of 3
  1. #1
    kamikazii is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default help with Array searching

    Alright, so this is my first time posting something like this so you may have to forgive me on the details.
    I am trying to write a program that allows a user to enter a variable number of student names and exam scores and then let them ask about the score of individual students by name.Where They should only be able to put in the names and scores once, but they can ask about as many students as they want until they don't want to ask about any more student's grades.

    I have created the two arrays, but i am not sure what to do next..here is what i have so far!

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int[] scores;
    String[] student;

    //Array for storing the first names of the Students
    student = new String[6];
    System.out.println("First Name of Students: ");
    for (int i = 0; i < 6; i++) {
    System.out.print("student: ");
    student[i] = sc.next();
    }

    //Array for the Scores of the Students
    scores = new int[6];
    for (int j = 0; j < 6; j++) {
    System.out.print("Exam score: ");
    scores[j] = sc.nextInt();
    }

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

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: help with Array searching

    Ehm. That won't work. You'll have a bunch of names and a bunch of unrelated scores. I'd implement a class Student that encapsulates the name and score for one student. Then fill a List or Array with these objects.

    And please use code tags when posting code.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: help with Array searching

    They look like parallel arrays to me.
    But then I would load them as Name/Score, Name/Score.
    So one loop rather than two.

    Of course if the OP has done classes then a Student class would be the proper way forward.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 3
    Last Post: 11-25-2011, 12:38 AM
  2. Searching array elements for keywords
    By Nanomech in forum New To Java
    Replies: 2
    Last Post: 08-13-2011, 01:46 PM
  3. Searching through Array of Objects
    By coopc in forum New To Java
    Replies: 6
    Last Post: 04-26-2011, 03:32 PM
  4. Replies: 3
    Last Post: 03-15-2011, 12:24 PM
  5. Searching In a String Array - Problem
    By DillMan in forum New To Java
    Replies: 4
    Last Post: 12-07-2008, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •