![](https://2.bp.blogspot.com/-FXkb84tWS_Q/VhUetgpL57I/AAAAAAAAB6I/fvNLQwpVTxI/s1600/Lab%2BJava%2BPetani%2BKode.png)
In the case of yesterday's circular area program , we use the power of two to calculate the area of a circle. The power of two can be written by multiplying a variable or number to be raised by two. For example, it can be written . But how about a lot of rank? for example . There's no way we would multiply that much in the code. Therefore, we need a rank function to calculate it. Java already provides a rank function that can be used at any time. This function has two parameters, namely the number to be raised and the rank.
r2
r*r
4112
Math.pow (number, rank);
Example program, please create a new class named Rank in the meeting package3 . Then follow the following code: The program code above will produce an output: 32, because 2 5will produce 32.![](https://2.bp.blogspot.com/-Xh3_ALdPrug/ViJaw7ln3CI/AAAAAAAACDg/J4YeXknsEyc/s1600/program%2Bpemangkatan%2Bbilangan%2Bdi%2Bjava.png)
![](https://4.bp.blogspot.com/-LliT4M85udU/ViJbVl3k9CI/AAAAAAAACDo/5EEkMlk4bLk/s1600/output%2Bprogram%2Bpemangkatan%2Bdi%2Bjava.png)
Sumber: https://www.petanikode.com/java-pangkat/
0 Komentar untuk "Java learning: How to Calculate Rank Operations"
Silahkan berkomentar sesuai artikel