Discussion – Lesson 7 - Arrays in Java
BackComments
4 messages from 4 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Comments
I'm beginner in Java, but I have a feeling that using "BinarySearch" afte
"Sort" gives only one info at the end - if value is on array or not. It doesn't
matter in what position value is found since after "Sort" its not original array
anymore.
What could be more interesting is to create 2 arrays (for example array 1 =
fruts, array 2 = price) then enter name of fruit (for example "apple") then find
it position in array1 and then check value of same element in array 2 (so, get
price). Or do the same, but use one 2 dimension array.
I think that following example will be more interesting:
Scanner scanner = new Scanner(System.in);
// DEFINE array
String[] simpsons = {"Homer", "Marge", "Bart", "Lisa", "Maggie"};
int[] age = {50, 45, 12, 15, 1};
// ask name
System.out.println("Age of what person you want to know?");
String input2 = scanner.nextLine();
int position2 = Arrays.asList(simpsons).indexOf(input2);
System.out.println(age[position2]);
4 messages from 4 displayed.