Computer Science, asked by rosy3434, 7 months ago

5. Write a program in Java to accept 10 different 3 digit numbers in array and
calculate the sum of all numbers that is multiple of both 2 and 3 present in
that array using function.
Instance variables/Data members:
int a []
: to store the 10 numbers
Rest of the variables can be assumed as required according to the logic of the
program
Instance Methods:
void accept ()
: to accept 10 different 3 digit numbers in an array
using an input statement.
boolean check (int x) : to check the argument is multiple of both 2 and 3
or not. If yes then it returns true otherwise it returns false.
void display ( )
: to display all the numbers and their position in that
array that is multiple of both 2 and 3. Finally display the sum of all numbers
that is multiple of both 2 and 3 present in that array with proper message.
Write a main () to call the method using an object to perform the task.​

Answers

Answered by muskanchoudhuri
0

search

Sign In

Home

Courses

Hire With Us

Algorithmskeyboard_arrow_down

Data Structureskeyboard_arrow_down

Languageskeyboard_arrow_down

Interview Cornerkeyboard_arrow_down

GATEkeyboard_arrow_down

CS Subjectskeyboard_arrow_down

Studentkeyboard_arrow_down

GBlog

Puzzles

What's New ?

Program to print Sum of even and odd elements in an array

Last Updated: 11-05-2020

Prerequisite – Array Basics

Given an array, write a program to find the sum of values of even and odd index positions separately.

Examples:

Input : arr = {1, 2, 3, 4, 5, 6}

Output :Even index positions sum 9

Odd index positions sum 12

Explanation: Here, n = 6 so there will be 3 even

index positions and 3 odd index positions in an array

Even = 1 + 3 + 5 = 9

Odd = 2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}

Output : Even index positions sum 160

Odd index positions sum 170

Explanation: Here, n = 7 so there will be 3 odd

index positions and 4 even index positions in an array

Even = 10 + 30 + 50 + 70 = 160

Odd = 20 + 40 + 60 = 120

Similar questions