repl.it
@maniero/

MultiplyBigInteger

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.math.*;

class Main {
	public BigInteger totali;
	public BigInteger totalp;
	public Main(BigInteger totali, BigInteger totalp) {
	    this.totali = totali;
	    this.totalp = totalp;
	}
	public static void main(String[] args) {
	    new Main(BigInteger.ZERO, BigInteger.ONE).parImpar();
	}
	public void parImpar() {
	    for (BigInteger i = BigInteger.ONE; i.compareTo(BigInteger.valueOf(100)) != 0; i = i.add(BigInteger.ONE)) {
	        if (i.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO) != 0) totali = totali.add(i);
	        else totalp = totalp.multiply(i);
	    }
	    System.out.println("Total pares " + totalp);
	    System.out.println("Total impar " + totali);
	}
}

//https://pt.stackoverflow.com/q/388636/101