Computer Science, asked by Annamr4236, 3 days ago

write a program in java to enter 10 numbers and print the average of those numbers which are multiple of 5

Answers

Answered by Kittumishrakrishi
1

Answer:

java.util.*

class abc

{

public static void main(string args[]){

Scanner abc = new Scanner (System.in);

S.o.pln("enter 1 no");

int a =abc .Int;

S.o.pln("enter 2no");

int b =abc .Int;

S.o.pln("enter 3no");

int c =abc .Int;

S.o.pln("enter 4no");

int d =abc .Int;

S.o.pln("enter 5 no");

int e=abc .Int;

S.o.pln("enter 6no");

int f=abc .Int;

S.o.pln("enter 7 no");

int g=abc .Int;

S.o.pln("enter 8 no");

int h=abc .Int;

S.o.pln("enter 9no");

int i =abc .Int;

S.o.pln("enter 10no");

int j =abc .Int;

if (no/5)

avg=add of no /no

else

S.opln("multiple of 5");

}

}

Answered by BrainlyProgrammer
6

Answer:

//Program to print the average of those which are multiple of 5

import java.util.*;

class abc{

public static void main (String ar []){

Scanner sc= new Scanner(System.in);

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

int n=0,s=0,c=0;

for(int I=1;I<=10;I++){

n=sc.nextInt();

if(n%5==0){

s+=n;

c++;

}

}

if(c!=0){

double avg=s/c;

System.out.println("Average:"+avg);

}

}

}

Hint:-

  • Accept 10 numbers inside loop
  • Each iteration, check if each number is divisible by 5 or not
  • Yes? Find the sum (variable s) at the same time increase the value of counter variable (variable c)
  • Formula of average=sum/count
  • Outside the loop, print the average.
Attachments:
Similar questions