How to solve an indefinite integral in java?

How to solve java method: findLast, findMax, findIndexOfMax, Range....?

  • I'm totally new to java....and got stuck with this homework....(due for the next couple days): I have done 3 of them and stuck at question #4.... I don't expect anyone to do the work, just to help me out to get the idea of how to do it or something like that.... 1.Write and test a method count() that MUST USE a for_each loop to count and return the number of elements in an int array e.g. int a[] = {7,8,9,9,8,7}; System.out.println(count(a)); <- outputs 6. 2. Write and test a method sum() that calculates and returns the sum of the elements in an int array e.g. int a[] = {7,8,9,9,8,7}; System.out.println(sum(a)); <- outputs 48 3.Write and test a method average() that calculates and returns the average (in floating point) of the elements in an int array e.g. int a[] = {7,8,9,9,8,7}; System.out.println(average(a)); <- outputs 8.0 4. Write and test a method findLast() that searches an int array for the last occurrence of a value. Returns the index if found, -1 if not found e.g. int a[] = {7,8,9,9,8,7}; System.out.println(findLast(a, 8)); <- outputs 4 System.out.println(findLast(a, 2)); <- outputs -1

  • Answer:

    you use a for loop... private int findLast( int[] arr, int value ) { int indexOf = -1; for( int i = 0; i< arr.length; i++) { if( arr[i] == value ) { indexOf = i; } } return indexOf; }

sore at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.