1 answer

Methods with arrays in java

Question:

I have to write a method that will output the following:Please enter 10numbers: 5 3 2 8 14 22 5 3 20 3
Sum of numbers is:85
New array contents is: 86 5 11 17 25 8 6 23 6the method must add all integers in array and also display thearray with each element incremented by the last elementamount.My program is not summing the array properly and also notputting spaces while displaying new array.Here is what Ihave so far.import java.util.*;
public class Spring2004Tues
{
public static void main(String[] args) {
Scanner keyboard = newScanner(System.in);
// declare the array ofintegers
int[] theArray = newint[10];
int i;//loop counter
int sum = 0; // willstore sum of array values
System.out.println("Name: Christopher Kaplan, final exam problem 1,CS 107");
System.out.print("Pleaseenter 10 numbers: ");
for (i=0; i<10; i++){
// write the statement using cin to read in each number into arrayelement i
theArray[i] = keyboard.nextInt();
}
sum(theArray);// Call the function to getthe sum
// Function should also increment array values
System.out.println("Sum of numbers is: " + sum(theArray));
System.out.print("New array contents is: ");//+Arrays.toString(theArray));
for (i=0; i<10; i++) {
// display the contents of the array
System.out.print(theArray[i]);
}
}
public static int sum(int[] array){
int sum = 0;
for (int i=0;i<array.length;i++){
array[i] = array[i] + array[array.length -1];
sum = sum + array[i];
}
return sum;
}
}
I will rateASAP if someone can help me resolve this issue.

Answers

I found the problem..

Similar Solved Questions

1 answer
Explain the Typical medical treatment for Malabsorption syndrome. Provide a thorough response, a few paragraphs citing...
Explain the Typical medical treatment for Malabsorption syndrome. Provide a thorough response, a few paragraphs citing examples of treatment and what the treatment modalities do...
1 answer
Question 9 (1 point) Find the value of x. Round the lengths of segments to the...
Question 9 (1 point) Find the value of x. Round the lengths of segments to the nearest tenth and the measure of angles to the nearest degree. 12.5 a) 40 b) 56 c) 34 d) 55 15...
1 answer
I have a couple questions that I'm looking for help explaining as my textbook doesn't go...
I have a couple questions that I'm looking for help explaining as my textbook doesn't go into great detail on either subjects. Thanks! 1.) What was the “Great Inflation." What are the basic causes and types of inflation that existed? 2.) According to The Gordon Growth Model, what a...
1 answer
What parts of the digestive system are involved with mechanical digestion?
What parts of the digestive system are involved with mechanical digestion?...
1 answer
How is the area of a wall calculated?
How is the area of a wall calculated?...
1 answer
Complex Analysis Use a contour to evaluate $25 1 (2+cos 0) dᎾ
Complex Analysis Use a contour to evaluate $25 1 (2+cos 0) dᎾ...
1 answer
Find the standard deviation, s, of sample data summarized in the frequency distribution table given below...
Find the standard deviation, s, of sample data summarized in the frequency distribution table given below by using the formula below, where x represents the class midpoint, f represents the class frequency, and n represents the total number of sample values. Also, compare the computed standard devia...
1 answer
The following reaction of great industrial importance A rightarrow B is to be carried out under...
The following reaction of great industrial importance A rightarrow B is to be carried out under the following reaction conditions: T = 25 degree C, C_A0 = 0.15mol/lt and volumetric flow rate 0.5lt/min. The reaction is first order with respect to A and the rate constant, k = 0.158min^-1. The process ...
1 answer
Competitive firm produces output using three fixed factors and one variable factor. The firm’s short-run production...
competitive firm produces output using three fixed factors and one variable factor. The firm’s short-run production function is q = 305x − 2x2, where x is the amount of the variable factor used. The price of the output is £2 per unit and the price of the variable factor is £1...
1 answer
Country A starts with real GDP per capita equal to $40,000 and Country B starts with...
Country A starts with real GDP per capita equal to $40,000 and Country B starts with real GDP per capita equal to $2,000. Today the RGDP per capita in A is ___ times the value in B. Country A is growing at a rate of 3.5% per year and Country B is growing at a rate of 7% per year. Assume these growth...
1 answer
Kwantum Corporation has total assets of $3,600,000, common stock of $936,000, and retained earnings of $570,000...
Kwantum Corporation has total assets of $3,600,000, common stock of $936,000, and retained earnings of $570,000 at December 31, 2022. What are the creditors' claims on their assets at that date? $2,094,000 $3,966,000 $1,506,000 $3,234,000...
1 answer
The Edmond Theatre is contemplating charging a different price for a ticket to an afternoon show...
the Edmond Theatre is contemplating charging a different price for a ticket to an afternoon show than for the same film that evening. In adopting a price strategy, the Edmond must consider that fixed costs are 20$ per week and variable costs are .50$ per customer. Pa = 8.5 - 0.4 Qa Pb = 4.5 - 0.2 Qb...
1 answer
Please help ASAP in these practice questions. thank you so much in advance! Temple University Department...
please help ASAP in these practice questions. thank you so much in advance! Temple University Department of Chemistry Chemistry 2201 - Organic Chemistry Exam 2 October 31, 2019 Sieburth - Motsch Answer all questions lepibly in the space provided. Sec. 012 Tues 14:00 Sec013 Wed 10:00 Sec. 014 T...
1 answer
Minden Company introduced a new product last year for which it is trying to find an...
Minden Company introduced a new product last year for which it is trying to find an optimal selling price. Marketing studies suggest that the company can increase sales by 5,000 units for each $2 reduction in the selling price. The company's present selling price is $97 per unit, and variable ex...
1 answer
Please show inbetween steps im confused how to treat the negative sign on the four? i...
please show inbetween steps im confused how to treat the negative sign on the four? i think i divide out the four first since thqt is an lcd of the four in the g(x)). 2,15, 2020 207 HW f(x) = 3x-4 f(g(x)) = W I 1-4 and g(x)= 1 1 1 2 Find flg(x)) and off) and determine whether the pair of func...