Write a program that generates 60 random integers in interval [0,100]. Your program computes the average of the numbers that are divisible by 3. public static void main(String[] args) { int sum=0, count=0; for(int i=1; i<=60; i++) { int num = (int) (Math.random()*101); if(num%3==0) { sum = sum+num; count = count+1; } } double avg=(double)sum/count; System.out.println("Average: "+ avg); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter