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
The help desk received a call from a user who cannot get any print jobs to print on the locally shared printer. While questionin
iragen [17]

Answer:

Power cycle the printer

Explanation:

To power cycle a device means to turn it off and turn it back on again.This might mean switching the power to OFF and then ON again or may require physically unplugging the device and then plugging it back in again.Power cycling the device erases the RAM and allows it to boot up with fresh information.

Typically it is a good idea to wait 5 to 10 seconds before turning the device back on to make sure it has chance to fully reset.

3 0
3 years ago
Read 2 more answers
Question 1 of 10
Basile [38]

Answer:

A, C, and D I believe.

Explanation:

I'm in the same class as you lol

6 0
2 years ago
Discuss, in brief thedifferent variations of BLAST. (Maximum 5 innumber)
schepotkina [342]

Answer:

Five variations od BLAST are as following:-

  1. BLASTP
  2. BLASTX
  3. TBLASTX
  4. BLASTN
  5. TBLASTN

Explanation:

BLASTP - Searches a protein database with a protein sequence.

BLASTX - This program searches protein database using a translated nucleotide sequence.

TBLASTX - Searches DNA databases using a protein query.

BLASTN -Searches a nucleotide sequence against DNA database.

TBLASTN - Searches nucleotide sequence to a DNA database.

5 0
4 years ago
What can the tab key do
bulgar [2K]
Answer: it indents

Explanation:
8 0
3 years ago
What is the gear ratios of a gear train with an input gear of 48 teeth and an output gear of 12?
kondor19780726 [428]

Answer:

D: 4:1

Explanation:

If you divide 48 by 12, you get 4. 12 is 1/4 of 48. Therefore, you keep it at 4:1.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Arpanet was developed by the united states so that there was a communication network that would survive a nuclear war. True or F
    11·1 answer
  • Which statement accurately describes the process for storing AutoRecovered files?
    7·2 answers
  • What is an electronic path over which data can travel.
    7·1 answer
  • A grade of B is worth Grade points<br><br><br> A) 3.0<br> B) 80<br> C)2.0<br> D)4.0
    13·2 answers
  • This document shows a student's education and career goals and a way to achieve those goals.
    8·1 answer
  • Animations and transitions are added from the _____.
    11·2 answers
  • Create the following new exceptions: PokemonException, which extends the Exception class. It must have a no-parameter constructo
    13·1 answer
  • What two benefits are a result of configuring a wireless mesh network? Check all that apply.
    12·1 answer
  • What allows a programmer to write code quickly and efficiently for an action that must be repeated?
    14·1 answer
  • Can someone please do this java lab for me (100 point version)? Im really having trouble. (DO NOT GIVE FAKE, USELESS ANSWERS. I
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!