how to search in an array

i dont know the code to wrtie a java program that searches for names and grades in a program...can anyone write the code that searches for names and grades in an array?
[175 byte] By [search_java_in_array22a] at [2007-10-2 21:24:03]
# 1

> i dont know the code to wrtie a java program that

> searches for names and grades in a program...can

> anyone write the code that searches for names and

> grades in an array?

How about you give it a try, and post a specific question here if you run into problems.

This is a good place to start:

http://java.sun.com/docs/books/tutorial/java/data/arrays.html

Good luck.

prometheuzza at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...
# 2

> searches for names and grades in a program...can

> anyone write the code that searches for names and

> grades in an array?

No. Your homework is yours. And so should be done by you.

Grab a pen and some paper, write down how you would do it. Step by step.

mlka at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...
# 3

> i dont know the code to wrtie a java program that

> searches for names and grades in a program...can

> anyone write the code that searches for names and

> grades in an array?

just the most simple pseudocode, might help you to get start.

// arg[0] is your inputted name

// you have arrays of string and double

int length = total number of names you have

String[] names = new String[length]

double[] grades = new double[length]

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

if (names[i].equals(arg[0])) {

System.out.println(names[i] + " got " + grades[i])

}

}

that's it!>

TikkyChaia at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...
# 4
This sort of OP is likely to make a new thread, copy paste this pseudo-code in there as their own attempt, and get someone else to "just finish the last bits that don't work".
Lokoa at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...
# 5
> i dont know the code to wrtie a java program that> searches for names and grades in a program...can> anyone write the code that searches for names and> grades in an array?yes. I can
georgemca at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...
# 6

> i dont know the code to wrtie a java program that

> searches for names and grades in a program...can

> anyone write the code that searches for names and

> grades in an array?

Let me give you some facts:

1. Yes, most of us can.

2. No, most of us are not likely to write that code for you.

3. It makes a difference HOW the names and grades are stored in the array

Is this a 2D array, with names indexed by [0] and grades indexed by [1]. Or is this a 1D array with names indexed by [i*2] and grades indexed by [i*2 + 1]?

Or is it two completely separate arrays, with the grades of a person indexed in the same position in a grades array as the names are indexed in the names array.

this makes a big difference as to how you should proceed.

By looking at your post, however, you haven't even given the slightest bit of thought to that, yet, because you didn't post that information.

If you don't at least TRY to figure this out for yourself, you're not going to find much help here.

- Adam

guitar_man_Fa at 2007-7-14 0:34:57 > top of Java-index,Java Essentials,Java Programming...