Advertisement
murlokito

FP04E02

Oct 26th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. package fp04;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.math.*;
  6.  
  7. /**
  8.  *
  9.  * @author aluno
  10.  */
  11. public class FP04 {
  12.  
  13.     public static void main(String[] args) throws IOException {
  14.        
  15.         int n, i, r;
  16.         double d;
  17.        
  18.         Contador neg, pos;
  19.        
  20.         neg = new Contador();
  21.         pos = new Contador();
  22.        
  23.         System.out.println("Introduza um numero:");
  24.         Scanner teclado = new Scanner(System.in);
  25.         n = teclado.nextInt();
  26.        
  27.         for(i=1; i<=n; i++){
  28.         d = Math.random();
  29.         r = (int)(d*200 - 100);
  30.        
  31.         if(r<0)
  32.         neg.incConta();
  33.         else
  34.         pos.incConta();
  35.         }
  36.        
  37.        
  38.         System.out.println("Positivos:" + pos + "\n" + "Negativos:" + neg);
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement