fork download
  1. import java.math.*;
  2.  
  3. class ParImpar {
  4. public BigInteger totali;
  5. public BigInteger totalp;
  6. public ParImpar(BigInteger totali, BigInteger totalp) {
  7. this.totali = totali;
  8. this.totalp = totalp;
  9. }
  10. public static void main(String[] args) {
  11. new ParImpar(BigInteger.ZERO, BigInteger.ONE).parImpar();
  12. }
  13. public void parImpar() {
  14. for (BigInteger i = BigInteger.ONE; i.compareTo(BigInteger.valueOf(101)) != 0; i = i.add(BigInteger.ONE)) {
  15. if (i.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO) != 0) totali = totali.add(i);
  16. else totalp = totalp.multiply(i);
  17. }
  18. System.out.println("Total pares " + totalp);
  19. System.out.println("Total impar " + totali);
  20. }
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/388636/101
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
Total pares 34243224702511976248246432895208185975118675053719198827915654463488000000000000
Total impar 2500