Is there another way to get the index without using the index of the array? ex. Not using Array[5]
So, I was wondering if there is any way to get the Highest Name without using Names[5] ?
int points = 68, 87, 91, 30, 56, 99, 91 ;
String Names = "Billon", "Bob", "Barbie", "Beny", "Bardon", "Becks", "Benji" ;
showHighest(scores, Names);
int a = findThatName(Names, "Benji");
if (a == -1)
System.out.print("nBenji is not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
a = findThatName(Names, "Fed");
if (a == -1)
System.out.print("nFed was not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
}
public static void showHighest(int points, String Names)
int max = points[0];
for (int a = 1; a < points.length; a++)
if (points[a] > max)
max = points[a];
System.out.printf("Highest Name: %s Highest Points: %s", Names[5], max);
public static int findThatName(String Names, String name)
int index = -1;
for (int a = 0; a < Names.length; a++)
if (Names[a].equals(name))
index = a;
break;
return index;
}
Specifically, within the showBest method. Instead of using Names[5], am I able to get something like Names[i]? Or maybe how would I use the index of the max score to be the same index of Names?
edit: Sorry I had to change the wording of the code...
java arrays indexing
add a comment |
So, I was wondering if there is any way to get the Highest Name without using Names[5] ?
int points = 68, 87, 91, 30, 56, 99, 91 ;
String Names = "Billon", "Bob", "Barbie", "Beny", "Bardon", "Becks", "Benji" ;
showHighest(scores, Names);
int a = findThatName(Names, "Benji");
if (a == -1)
System.out.print("nBenji is not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
a = findThatName(Names, "Fed");
if (a == -1)
System.out.print("nFed was not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
}
public static void showHighest(int points, String Names)
int max = points[0];
for (int a = 1; a < points.length; a++)
if (points[a] > max)
max = points[a];
System.out.printf("Highest Name: %s Highest Points: %s", Names[5], max);
public static int findThatName(String Names, String name)
int index = -1;
for (int a = 0; a < Names.length; a++)
if (Names[a].equals(name))
index = a;
break;
return index;
}
Specifically, within the showBest method. Instead of using Names[5], am I able to get something like Names[i]? Or maybe how would I use the index of the max score to be the same index of Names?
edit: Sorry I had to change the wording of the code...
java arrays indexing
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a classPlayerScorethat holds both the name and the score in a single object.
– chrylis
Nov 10 at 5:18
add a comment |
So, I was wondering if there is any way to get the Highest Name without using Names[5] ?
int points = 68, 87, 91, 30, 56, 99, 91 ;
String Names = "Billon", "Bob", "Barbie", "Beny", "Bardon", "Becks", "Benji" ;
showHighest(scores, Names);
int a = findThatName(Names, "Benji");
if (a == -1)
System.out.print("nBenji is not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
a = findThatName(Names, "Fed");
if (a == -1)
System.out.print("nFed was not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
}
public static void showHighest(int points, String Names)
int max = points[0];
for (int a = 1; a < points.length; a++)
if (points[a] > max)
max = points[a];
System.out.printf("Highest Name: %s Highest Points: %s", Names[5], max);
public static int findThatName(String Names, String name)
int index = -1;
for (int a = 0; a < Names.length; a++)
if (Names[a].equals(name))
index = a;
break;
return index;
}
Specifically, within the showBest method. Instead of using Names[5], am I able to get something like Names[i]? Or maybe how would I use the index of the max score to be the same index of Names?
edit: Sorry I had to change the wording of the code...
java arrays indexing
So, I was wondering if there is any way to get the Highest Name without using Names[5] ?
int points = 68, 87, 91, 30, 56, 99, 91 ;
String Names = "Billon", "Bob", "Barbie", "Beny", "Bardon", "Becks", "Benji" ;
showHighest(scores, Names);
int a = findThatName(Names, "Benji");
if (a == -1)
System.out.print("nBenji is not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
a = findThatName(Names, "Fed");
if (a == -1)
System.out.print("nFed was not on the list");
else
System.out.printf("nName: %s had %s points", Names[a], points[a]);
}
public static void showHighest(int points, String Names)
int max = points[0];
for (int a = 1; a < points.length; a++)
if (points[a] > max)
max = points[a];
System.out.printf("Highest Name: %s Highest Points: %s", Names[5], max);
public static int findThatName(String Names, String name)
int index = -1;
for (int a = 0; a < Names.length; a++)
if (Names[a].equals(name))
index = a;
break;
return index;
}
Specifically, within the showBest method. Instead of using Names[5], am I able to get something like Names[i]? Or maybe how would I use the index of the max score to be the same index of Names?
edit: Sorry I had to change the wording of the code...
java arrays indexing
java arrays indexing
edited Nov 10 at 6:16
asked Nov 10 at 5:12
c.c.
56
56
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a classPlayerScorethat holds both the name and the score in a single object.
– chrylis
Nov 10 at 5:18
add a comment |
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a classPlayerScorethat holds both the name and the score in a single object.
– chrylis
Nov 10 at 5:18
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a class
PlayerScore that holds both the name and the score in a single object.– chrylis
Nov 10 at 5:18
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a class
PlayerScore that holds both the name and the score in a single object.– chrylis
Nov 10 at 5:18
add a comment |
2 Answers
2
active
oldest
votes
You can store both max value and its index.
int index = 0;
int max = scores[0];
for (int i = 1; i < scores.length; i++)
if (scores[i] > max)
index = i;
max = scores[i];
System.out.printf("Max Name: %s Max Score: %s", sNames[index], max);
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice theandforifstatement
– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
add a comment |
we should do this in java way, or the Object Oriented way.
For that we will need a Student class.
public class Student implements Comparable<Student>
private Integer score;
private String name;
public Student()
super();
public Student(Integer score, String name)
super();
this.score = score;
this.name = name;
public Integer getScore()
return score;
public void setScore(int score)
this.score = score;
public String getName()
return name;
public void setName(String name)
this.name = name;
@Override
public int compareTo(Student o)
return this.score.compareTo(o.getScore());
@Override
public String toString()
return "Student [score=" + score + ", name=" + name + "]";
Then we can use this Student class anywhere and play around with the list of students as we want, like below.
public class Driver {
public static void main(String args)
Student s1 = new Student(67, "Billy");
Student s2 = new Student(86, "Bobbi");
Student s3 = new Student(90, "Barbara");
Student s4 = new Student(20, "Beni");
Student s5 = new Student(55, "Baron");
Student s6 = new Student(98, "Becky");
Student s7 = new Student(90, "Ben");
List<Student> students = new ArrayList<>();
students.add(s1);
students.add(s2);
students.add(s3);
students.add(s4);
students.add(s5);
students.add(s6);
students.add(s7);
System.out.println("Minimum score student is :");
System.out.println(getMinScoreSudent(students));
System.out.println("nMaximum score student is :");
System.out.println(getMaxScoreSudent(students));
System.out.println("nAll Sudents :");
printStudentsInConsole(students);
public static Student getMinScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
return students.get(0);
public static Student getMaxScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore).reversed());
return students.get(0);
public static void printStudentsInConsole(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
students.stream().forEach(student -> System.out.println(student));
This prints below message in console.
Minimum score student is :
Student [score=20, name=Beni]
Maximum score student is :
Student [score=98, name=Becky]
All Sudents :
Student [score=20, name=Beni]
Student [score=55, name=Baron]
Student [score=67, name=Billy]
Student [score=86, name=Bobbi]
Student [score=90, name=Barbara]
Student [score=90, name=Ben]
Student [score=98, name=Becky]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236170%2fis-there-another-way-to-get-the-index-without-using-the-index-of-the-array-ex%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can store both max value and its index.
int index = 0;
int max = scores[0];
for (int i = 1; i < scores.length; i++)
if (scores[i] > max)
index = i;
max = scores[i];
System.out.printf("Max Name: %s Max Score: %s", sNames[index], max);
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice theandforifstatement
– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
add a comment |
You can store both max value and its index.
int index = 0;
int max = scores[0];
for (int i = 1; i < scores.length; i++)
if (scores[i] > max)
index = i;
max = scores[i];
System.out.printf("Max Name: %s Max Score: %s", sNames[index], max);
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice theandforifstatement
– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
add a comment |
You can store both max value and its index.
int index = 0;
int max = scores[0];
for (int i = 1; i < scores.length; i++)
if (scores[i] > max)
index = i;
max = scores[i];
System.out.printf("Max Name: %s Max Score: %s", sNames[index], max);
You can store both max value and its index.
int index = 0;
int max = scores[0];
for (int i = 1; i < scores.length; i++)
if (scores[i] > max)
index = i;
max = scores[i];
System.out.printf("Max Name: %s Max Score: %s", sNames[index], max);
answered Nov 10 at 5:16
M.kazem Akhgary
11.9k53272
11.9k53272
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice theandforifstatement
– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
add a comment |
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice theandforifstatement
– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
When I do this, the index name is right, Becky is the Max Name but the Max Score comes out to be 90 which is not the actual maximum.
– c.c.
Nov 10 at 5:23
@cin i think you forgot to put the braces. notice the
and for if statement– M.kazem Akhgary
Nov 10 at 5:28
@cin i think you forgot to put the braces. notice the
and for if statement– M.kazem Akhgary
Nov 10 at 5:28
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
Oh! You're right, I did forget about the curly braces! Sorry!
– c.c.
Nov 10 at 5:36
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
no worries! glad you got it right :)
– M.kazem Akhgary
Nov 10 at 5:38
add a comment |
we should do this in java way, or the Object Oriented way.
For that we will need a Student class.
public class Student implements Comparable<Student>
private Integer score;
private String name;
public Student()
super();
public Student(Integer score, String name)
super();
this.score = score;
this.name = name;
public Integer getScore()
return score;
public void setScore(int score)
this.score = score;
public String getName()
return name;
public void setName(String name)
this.name = name;
@Override
public int compareTo(Student o)
return this.score.compareTo(o.getScore());
@Override
public String toString()
return "Student [score=" + score + ", name=" + name + "]";
Then we can use this Student class anywhere and play around with the list of students as we want, like below.
public class Driver {
public static void main(String args)
Student s1 = new Student(67, "Billy");
Student s2 = new Student(86, "Bobbi");
Student s3 = new Student(90, "Barbara");
Student s4 = new Student(20, "Beni");
Student s5 = new Student(55, "Baron");
Student s6 = new Student(98, "Becky");
Student s7 = new Student(90, "Ben");
List<Student> students = new ArrayList<>();
students.add(s1);
students.add(s2);
students.add(s3);
students.add(s4);
students.add(s5);
students.add(s6);
students.add(s7);
System.out.println("Minimum score student is :");
System.out.println(getMinScoreSudent(students));
System.out.println("nMaximum score student is :");
System.out.println(getMaxScoreSudent(students));
System.out.println("nAll Sudents :");
printStudentsInConsole(students);
public static Student getMinScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
return students.get(0);
public static Student getMaxScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore).reversed());
return students.get(0);
public static void printStudentsInConsole(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
students.stream().forEach(student -> System.out.println(student));
This prints below message in console.
Minimum score student is :
Student [score=20, name=Beni]
Maximum score student is :
Student [score=98, name=Becky]
All Sudents :
Student [score=20, name=Beni]
Student [score=55, name=Baron]
Student [score=67, name=Billy]
Student [score=86, name=Bobbi]
Student [score=90, name=Barbara]
Student [score=90, name=Ben]
Student [score=98, name=Becky]
add a comment |
we should do this in java way, or the Object Oriented way.
For that we will need a Student class.
public class Student implements Comparable<Student>
private Integer score;
private String name;
public Student()
super();
public Student(Integer score, String name)
super();
this.score = score;
this.name = name;
public Integer getScore()
return score;
public void setScore(int score)
this.score = score;
public String getName()
return name;
public void setName(String name)
this.name = name;
@Override
public int compareTo(Student o)
return this.score.compareTo(o.getScore());
@Override
public String toString()
return "Student [score=" + score + ", name=" + name + "]";
Then we can use this Student class anywhere and play around with the list of students as we want, like below.
public class Driver {
public static void main(String args)
Student s1 = new Student(67, "Billy");
Student s2 = new Student(86, "Bobbi");
Student s3 = new Student(90, "Barbara");
Student s4 = new Student(20, "Beni");
Student s5 = new Student(55, "Baron");
Student s6 = new Student(98, "Becky");
Student s7 = new Student(90, "Ben");
List<Student> students = new ArrayList<>();
students.add(s1);
students.add(s2);
students.add(s3);
students.add(s4);
students.add(s5);
students.add(s6);
students.add(s7);
System.out.println("Minimum score student is :");
System.out.println(getMinScoreSudent(students));
System.out.println("nMaximum score student is :");
System.out.println(getMaxScoreSudent(students));
System.out.println("nAll Sudents :");
printStudentsInConsole(students);
public static Student getMinScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
return students.get(0);
public static Student getMaxScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore).reversed());
return students.get(0);
public static void printStudentsInConsole(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
students.stream().forEach(student -> System.out.println(student));
This prints below message in console.
Minimum score student is :
Student [score=20, name=Beni]
Maximum score student is :
Student [score=98, name=Becky]
All Sudents :
Student [score=20, name=Beni]
Student [score=55, name=Baron]
Student [score=67, name=Billy]
Student [score=86, name=Bobbi]
Student [score=90, name=Barbara]
Student [score=90, name=Ben]
Student [score=98, name=Becky]
add a comment |
we should do this in java way, or the Object Oriented way.
For that we will need a Student class.
public class Student implements Comparable<Student>
private Integer score;
private String name;
public Student()
super();
public Student(Integer score, String name)
super();
this.score = score;
this.name = name;
public Integer getScore()
return score;
public void setScore(int score)
this.score = score;
public String getName()
return name;
public void setName(String name)
this.name = name;
@Override
public int compareTo(Student o)
return this.score.compareTo(o.getScore());
@Override
public String toString()
return "Student [score=" + score + ", name=" + name + "]";
Then we can use this Student class anywhere and play around with the list of students as we want, like below.
public class Driver {
public static void main(String args)
Student s1 = new Student(67, "Billy");
Student s2 = new Student(86, "Bobbi");
Student s3 = new Student(90, "Barbara");
Student s4 = new Student(20, "Beni");
Student s5 = new Student(55, "Baron");
Student s6 = new Student(98, "Becky");
Student s7 = new Student(90, "Ben");
List<Student> students = new ArrayList<>();
students.add(s1);
students.add(s2);
students.add(s3);
students.add(s4);
students.add(s5);
students.add(s6);
students.add(s7);
System.out.println("Minimum score student is :");
System.out.println(getMinScoreSudent(students));
System.out.println("nMaximum score student is :");
System.out.println(getMaxScoreSudent(students));
System.out.println("nAll Sudents :");
printStudentsInConsole(students);
public static Student getMinScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
return students.get(0);
public static Student getMaxScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore).reversed());
return students.get(0);
public static void printStudentsInConsole(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
students.stream().forEach(student -> System.out.println(student));
This prints below message in console.
Minimum score student is :
Student [score=20, name=Beni]
Maximum score student is :
Student [score=98, name=Becky]
All Sudents :
Student [score=20, name=Beni]
Student [score=55, name=Baron]
Student [score=67, name=Billy]
Student [score=86, name=Bobbi]
Student [score=90, name=Barbara]
Student [score=90, name=Ben]
Student [score=98, name=Becky]
we should do this in java way, or the Object Oriented way.
For that we will need a Student class.
public class Student implements Comparable<Student>
private Integer score;
private String name;
public Student()
super();
public Student(Integer score, String name)
super();
this.score = score;
this.name = name;
public Integer getScore()
return score;
public void setScore(int score)
this.score = score;
public String getName()
return name;
public void setName(String name)
this.name = name;
@Override
public int compareTo(Student o)
return this.score.compareTo(o.getScore());
@Override
public String toString()
return "Student [score=" + score + ", name=" + name + "]";
Then we can use this Student class anywhere and play around with the list of students as we want, like below.
public class Driver {
public static void main(String args)
Student s1 = new Student(67, "Billy");
Student s2 = new Student(86, "Bobbi");
Student s3 = new Student(90, "Barbara");
Student s4 = new Student(20, "Beni");
Student s5 = new Student(55, "Baron");
Student s6 = new Student(98, "Becky");
Student s7 = new Student(90, "Ben");
List<Student> students = new ArrayList<>();
students.add(s1);
students.add(s2);
students.add(s3);
students.add(s4);
students.add(s5);
students.add(s6);
students.add(s7);
System.out.println("Minimum score student is :");
System.out.println(getMinScoreSudent(students));
System.out.println("nMaximum score student is :");
System.out.println(getMaxScoreSudent(students));
System.out.println("nAll Sudents :");
printStudentsInConsole(students);
public static Student getMinScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
return students.get(0);
public static Student getMaxScoreSudent(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore).reversed());
return students.get(0);
public static void printStudentsInConsole(List<Student> students)
Collections.sort(students, Comparator.comparing(Student::getScore));
students.stream().forEach(student -> System.out.println(student));
This prints below message in console.
Minimum score student is :
Student [score=20, name=Beni]
Maximum score student is :
Student [score=98, name=Becky]
All Sudents :
Student [score=20, name=Beni]
Student [score=55, name=Baron]
Student [score=67, name=Billy]
Student [score=86, name=Bobbi]
Student [score=90, name=Barbara]
Student [score=90, name=Ben]
Student [score=98, name=Becky]
edited Nov 10 at 7:07
answered Nov 10 at 5:49
janardhan sharma
2537
2537
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236170%2fis-there-another-way-to-get-the-index-without-using-the-index-of-the-array-ex%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Note that this organization is called parallel arrays and is asking for all sorts of trouble. Instead, create a class
PlayerScorethat holds both the name and the score in a single object.– chrylis
Nov 10 at 5:18