1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Pie
3 years ago
5

Write a method that returns the sum of all the elements of an array of ints that have an odd index.

Computers and Technology
1 answer:
wolverine [178]3 years ago
5 0

Answer:

import java.io.*;

import java.util.Scanner;

class Odd {

public static void main (String[] args) {

    Scanner ele=new Scanner(System.in);//creating a scanner object.

      int n,sum=0;//declaring n and sum and initializing sum with 0.

    n=ele.nextInt();//taking input of the n.

    int [] arr =new int[n];//declaring an array arr.

    for(int i=0;i<n;i++)

    {

        arr[i]=ele.nextInt();//taking input of the array.

    }

    for(int i=0;i<arr.length;i++)

    {

        if(i%2!=0)//adding to the if index is odd.

        {

            sum+=arr[i];

        }

    }

    System.out.println(sum);

}

}

Input:-

6

1 2 3 4 5 6

Output:-

12

Explanation:

First I have created an a scanner object ele. I have taken two integers n and sum, n for number of array elements and sum for calculating the sum of odd indexed elements hence initializing it with 0.Then I have created an array named arr.Then taking the input of the n and array elements.Then looping over the array and calculating the sum.

You might be interested in
What is a Computer ?and it's demerits​
kherson [118]

Answer:

Computer has making human life faster because of its incredible speed,Accuracy and storage, with which human can save anything and search it out easily when needed. We can say computer a versatile machine because it is very flexible in performing their jobs.

6 0
3 years ago
Read 2 more answers
the term that is used to describe how many bits are used in each pixel to show the number of colours used
Korolek [52]
Colour depth?????????????????????                              .
8 0
4 years ago
What is theory of knowledge?​
Karolina [17]
Theory of knowledge (TOK) plays a special role in the International Baccalaureate® (IB) Diploma Programme (DP), by providing an opportunity for students to reflect on the nature of knowledge, and on how we know what we claim to know.
4 0
3 years ago
#Draw patterns using fibonacci
agasfer [191]

Answer:

yidRYoYORoydzyrozoyrsoyraoyeahplhDogdaoyeayeoayorahdlHDLgksOyeayeazhldhdlHkdOyaoyaerhaahdLhKDoywaeya9yaeya9eeY9ey9

7 0
3 years ago
Review the HTML tags that we have gone over in this lesson. Research HTML tags on the web and identify two new tags. Use these t
NemiM [27]

Answer:

w3schools

Explanation:

there is a webiste called w3schools that really helped me through my web page design class, just click on learn html

4 0
3 years ago
Other questions:
  • HELLLLLP ill make you brainiest and ill give u a lot of points if you HELP ME Directions Part One.
    12·2 answers
  • Name the component used in first generation of computer​
    10·1 answer
  • Which of the following is not an advantage of using asynchronous data transmission
    15·1 answer
  • The principle of time preference requries a larger payment in the future than the present. Which situation best illustrates this
    12·1 answer
  • ) Which is true about the agile method?
    7·1 answer
  • What is computer. Write full form of mips​
    15·1 answer
  • Write a Python program segment, using a loop, to calculate and print the sum of the odd integers from 20 to 120. (Hint: 21 23 25
    13·1 answer
  • What's the answer plssss​
    10·1 answer
  • Type the correct answer in the box. Spell all words correctly. Kenny is designing a document for the employee motivation campaig
    8·1 answer
  • each data mining technique has its advantages and limitations. which data mining technique mimics the neural structure of the br
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!