Matemaatika
Enamik matemaatlistest tehetest on Pyhonis ja Javas sarnased:
Tehe |
Python |
Java |
---|---|---|
Liitmine |
a = 10
b = 5
print(a + b) # 15
|
int a = 10;
int b = 5;
System.out.println(a + b); // 15
|
Lahutamine |
a = 10
b = 5
print(a - b) # 5
|
int a = 10;
int b = 5;
System.out.println(a - b); // 5
|
Korrutamine |
a = 10
b = 5
print(a * b) # 50
|
int a = 10;
int b = 5;
System.out.println(a * b); //50
|
Jagamine |
a = 10
b = 5
print(a / b) # 2.0
|
double a = 10;
double b = 5;
System.out.println(a / b); // 2.0
|
Moodul |
a = 10
b = 5
print(a % b) # 0
|
int a = 10;
int b = 5;
System.out.println(a % b); // 0
|
Jäägita jagamine |
a = 10
b = 5
print(a // b) # 2
|
int a = 10;
int b = 5;
System.out.println(a / b); // 2
|
Ruutjuur |
import math
a = 10
b = 5
print(math.sqrt(a + b)) # 3.8729833
|
int a = 10;
int b = 5;
System.out.println(Math.sqrt(a + b)); // 3.8729833
|
Astmesse võtmine |
a = 10
b = 5
print(a ** b) # 100000
|
int a = 10;
int b = 5;
System.out.println(Math.pow(a, b)); // 100000
|
Logaritm |
import math
a = 10
b = 5
print(math.log(a, b)) # 1.43067655
|
int a = 10;
int b = 5;
System.out.println(Math.log(a) / Math.log(b)); // 1.43067655
|