Arithmetic average

Report a typo

Write a program that reads two numbers a a and b b from the keyboard and calculates and outputs to the console the arithmetic average of all numbers from the interval [a;b] [a; b] , which are divisible by 3 3 .

In the example below, the arithmetic average is calculated for the numbers on the interval [5;12] [-5; 12] . On this interval, there are 6 6 numbers divisible by 3 3 , namely: 3,0,3,6,9,12 -3, 0, 3, 6, 9, 12 . Their arithmetic average equals 4.5 4.5 .

The program input contains intervals, which always contain at least one number, which is divisible by 3 3 .

Remember that the int type cannot contain fractions. Use a double variable to store the precise result of the division.

Sample Input 1:

-5
12

Sample Output 1:

4.5
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// start coding here
}
}
___

Create a free account to access the full topic