I wanted help in regards to accessing the index then printing it. Below is the example and my desired output:
Input Format:
-Array Size
-string
-index to be printed
Input:
3
Joana
Kim
Nina
2
Desired Output:
Your friends are:
Joana
Kim
Nina
Your best friend is:
Nina
This is the code I made. The third input format is not satisfied as I am yet to figure out the code to determine the bestfriend. How should I code to get the index from the given value?
int words=input.nextInt();
String[] names=new String[words];
for(int counter=0;counter<words; counter++){
names[counter]=input.next();
}
System.out.println("Your friends are");
for(int counter=0;counter<words;counter++){
System.out.println(names[counter]);
names[counter]. So if you just want to check for the best friendnames[number_for_bestfriend]number_for_bestfriendbeing the last number on your input that you have to get.