1,105,594 Community Members

extract strings from an array

Member Avatar
plasticfood
Junior Poster
114 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.util.Scanner;
public class Highest{
public static void main (String [] args){

Scanner kb = new Scanner(System.in);

int scores [] = new int[3];
String names [] = new String [3];
int highest = scores [0];
String names1 = names [0];

for (int i = 0; i<3; i++){
   System.out.println("enter name and score: ");
   names[i] = kb.next();
   scores[i] = kb.nextInt();
      if (scores[i] > highest)
         highest = scores[i];
         names1 = names[i];

}



System.out.println(highest + names1);


}
}

i'm stuck on the part where i have to extract the name that associates with the highest score. it always prints out the last name that i enter instead of the one with the highest score.

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 
Question Answered as of 3 Years Ago by NormR1
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article