RcrdBrt

Untitled

Nov 14th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Riccardo {
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner(System.in);
  6.         int num = kb.nextInt();
  7.         int min = 0;
  8.         int max = kb.nextInt();
  9.         int val = 0;
  10.         boolean primoGiro = true;
  11.         for (int i = 0; i < num; i++, val = kb.nextInt()) {
  12.             if (primoGiro || val > max) {
  13.                 max = val;
  14.             }
  15.             if (primoGiro || val < min) {
  16.                 min = val;
  17.             }
  18.             primoGiro = false;
  19.         }
  20.         int tot = 0;
  21.         int confronti = 0;
  22.         for (int i = min; i <= max; i++) {
  23.             for (int j = 0; j <= max - min; j++, confronti++) {
  24.                 if (i > j) {
  25.                     tot++;
  26.                 }
  27.             }
  28.         }
  29.         double rapporto = tot / (double)confronti;
  30.  
  31.         System.out.println("Tot: " + tot + "; rapporto: " + rapporto);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment