@maniero/

MultiplyBigInteger

Java

No description

fork
loading
Files
  • Main.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5978446085377487","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEubWF0aC4qOwoKY2xhc3MgTWFpbiB7CglwdWJsaWMgQmlnSW50ZWdlciB0b3RhbGk7CglwdWJsaWMgQmlnSW50ZWdlciB0b3RhbHA7CglwdWJsaWMgTWFpbihCaWdJbnRlZ2VyIHRvdGFsaSwgQmlnSW50ZWdlciB0b3RhbHApIHsKCSAgICB0aGlzLnRvdGFsaSA9IHRvdGFsaTsKCSAgICB0aGlzLnRvdGFscCA9IHRvdGFscDsKCX0KCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKCSAgICBuZXcgTWFpbihCaWdJbnRlZ2VyLlpFUk8sIEJpZ0ludGVnZXIuT05FKS5wYXJJbXBhcigpOwoJfQoJcHVibGljIHZvaWQgcGFySW1wYXIoKSB7CgkgICAgZm9yIChCaWdJbnRlZ2VyIGkgPSBCaWdJbnRlZ2VyLk9ORTsgaS5jb21wYXJlVG8oQmlnSW50ZWdlci52YWx1ZU9mKDEwMCkpICE9IDA7IGkgPSBpLmFkZChCaWdJbnRlZ2VyLk9ORSkpIHsKCSAgICAgICAgaWYgKGkubW9kKEJpZ0ludGVnZXIudmFsdWVPZigyKSkuY29tcGFyZVRvKEJpZ0ludGVnZXIuWkVSTykgIT0gMCkgdG90YWxpID0gdG90YWxpLmFkZChpKTsKCSAgICAgICAgZWxzZSB0b3RhbHAgPSB0b3RhbHAubXVsdGlwbHkoaSk7CgkgICAgfQoJICAgIFN5c3RlbS5vdXQucHJpbnRsbigiVG90YWwgcGFyZXMgIiArIHRvdGFscCk7CgkgICAgU3lzdGVtLm91dC5wcmludGxuKCJUb3RhbCBpbXBhciAiICsgdG90YWxpKTsKCX0KfQoKLy9odHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMzg4NjM2LzEwMQ=="},"asBuffer":null},"loaded":true}}
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