Question

I am using Java to try and solve this problem. Suggestions on where I am going wrong?

PREVNEXT Workbench ? a Exercise 20662- WORK AREA RESULTS Write the definition of a method named sumArray that has one parameter, an array of ints. The method returns the sum of the elements of the array as an int. x9 of 9: 2018-07-10 12:58:15 -W SUBMIT 1 public int sumArray(int[] a) 2 int i; int sum = 0; for (í 0; í?a.length; ?++) sum += i; return sum; 7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
int[] intArray = new int[3];
intArray[0]=12;
intArray[1]=5;
intArray[2]=5;
System.out.println(sumarray(intArray));
  
}
public static int sumarray(int[] intArray)
{
int i;
int sum =0;
for(i = 0; i< intArray.length; i++)
sum = +i;
return sum;

}
}

Thanks have great day.

Add a comment
Know the answer?
Add Answer to:
I am using Java to try and solve this problem. Suggestions on where I am going...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java solve recursively without the use of loops or modifying the method signatures. /** *...

    Using Java solve recursively without the use of loops or modifying the method signatures. /** * Given a sorted input array a, return a sorted array of size a.length + 1, * consisting of all elements of array a and integer i. * * @param a an array that is sorted in a non-descending order * @param i an integer * @return a sorted array of size a.length + 1, consisting of all elements of * array a and integer...

  • Please merge all the codes below and add comments using JAVA Program. I need a complete...

    Please merge all the codes below and add comments using JAVA Program. I need a complete code which is the combination of the following codes: // Merges the left/right elements into a sorted result. // Precondition: left/right are sorted public static void merge(int[] result, int[] left,                                        int[] right) {     int i1 = 0;   // index into left array     int i2 = 0;   // index into right array     for (int i = 0; i < result.length; i++)...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • I am working on my java but I keep getting this one wrong. Method Name: arrayContains...

    I am working on my java but I keep getting this one wrong. Method Name: arrayContains Access modifier: Private Parameters: 1 integer named number Return type: boolean Purpose: This method returns a true or a false indicating if the number is present in an array or not. In order for this method to work, there must be an array already declared. Therefore, in the CLASS BLOCK, declare an array as follows: static int[] listof Numbers = {1, 2, 3, 4,...

  • 5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below....

    5. (40 Points) Write a complete Java class named ArrayMethods that implements the methods listed below. All the methods accept the following parameters: Parameters: intar An array of int values. int firstIndex The index of the first element to include in the sum. int lastIndex The index of the last element to include in the sum. Please note that all methods must verify the validity of first Index and lastIndex. public static int sum(int[] arr, int first Index, int lastIndex)...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

  • Need help with this Java project implementing an interpolation search, bolded the missing parts: /**   ...

    Need help with this Java project implementing an interpolation search, bolded the missing parts: /**    A class that implements an interpolation search and    a binary search of a sorted array of integers.    @author Frank M. Carrano    @author Timothy M. Henry    @version 4.0 */ public class SearchComparer {    private int[] a;    private int interpolationSearchCounter;    private int binarySearchCounter;    private static final int CAPACITY = 50;    public SearchComparer(int[] array, int n)    {...

  • I was wondering if I could get some help with a Java Program that I am...

    I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...

  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT