Get up to 80 % extra points for free! More info:

Discussion – Lesson 7 - Arrays in Java

Back

 

Comments
Avatar
modi a jawo
Member
Avatar
modi a jawo:4/18/2017 4:22

Hello, i want a much simplified explanation on loops and arrays. who can help me please?

 
Reply
4/18/2017 4:22
Avatar
Shecy
Member
Avatar
Shecy:6/21/2017 15:50

lots of great info, Excellent!

 
Reply
6/21/2017 15:50
Avatar
Alex CHERNOV
Member
Avatar
Alex CHERNOV:8/2/2020 16:00

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.

 
Reply
8/2/2020 16:00
Avatar
Alex CHERNOV
Member
Avatar
Replies to Alex CHERNOV
Alex CHERNOV:8/2/2020 16:12

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]);
Edited 8/2/2020 16:14
 
Reply
8/2/2020 16:12
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

4 messages from 4 displayed.