lundi 9 mars 2020

Finding closest number to average of 3 random numbers

I need to find the closest number to average of 3 random numbers.
Program will generate a, b and c, calculate average from this numbers and then show us which of the random numbers is closest to our average.
I have got this right now:

import java.util.Random;

public class AvgRnd {

public static void main(String[] args) {
    Random rnd = new Random();
    int a = rnd.nextInt(11);
    int b = rnd.nextInt(37)-13;
    int c = rnd.nextInt(54)+34;
    System.out.println(a+"  "+b+"  "+ c);
    int avg = (a+b+c)/3;
    System.out.println(avg);
}
}



Aucun commentaire:

Enregistrer un commentaire