Computer Science, asked by kfuzail321, 9 months ago

Question 1:
Write a program to input an array B[], of size 20 and Print the SUM of all the elements
which are divisible by 3.
[5]
Question 2:

Answers

Answered by bhoomidarak
1

Answer:

In Java:

Explanation:

import java.util.Scanner;

class input

{

public static void main()

{

Scanner sc=new Scanner(System.in);

int B[]=new int[20];

int sum=0;

boolean chk=false;

System.out.println("Enter your numbers");

for (int x=0; x<B.length;x++)

{

int num=sc.nextInt();

B[x]=num;

if (B[x] % 3 == 0)

{

sum+=B[x];

chk=true;

}

}//for loop ends here

if (chk==false)

{

System.out.println("None of the numbers were divisible by 3");

}

else

{

System.out.println("Sum of the divisible numbers is: " + sum);

}

}//main ends here

}//class ends here

Hope this helps:)

Mark it as the Brainliest if it did help!!

Similar questions