Computer Science, asked by ramishkhan15, 5 hours ago

WAP to input 10 numbers and print the average of double digit numbers which are ending with 6.
write full bluej script.​

Answers

Answered by anindyaadhikari13
1

Solution.

The given co‎‎de is written in Java.

import java.util.*;

public class AvgNum{

   public static void main(String s[]){

       Scanner sc=new Scanner(System.in);

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

       float sum=0.0f,counter=0.0f;

       for(int i=0;i<10;i++){

           System.out.print(">> ");

           int x=sc.nextInt();

           if(x>9&&x<99 && x%10==6){

               sum+=x;

               counter++;

           }

       }

       sc.close();

       sum/=counter;

       System.out.println("The average of the double digit numbers is: "+sum);

   }

}

Here, we will ask the user to enter ten integers.

If the number is a 2 digit number ending with 6, we will add the numbers to sum variable. At the same time, the counter variable is incremented.

The counter variable counts how many such numbers are present.

Then, the sum is divided by counter to get the average.

The average is now displayed on the screen.

See attachment for output.

Attachments:
Similar questions