Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Square-but-not-cube/Java/square-but-not-cube.java
Normal file
24
Task/Square-but-not-cube/Java/square-but-not-cube.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
public class SquaresCubes {
|
||||
public static boolean isPerfectCube(long n) {
|
||||
long c = (long)Math.cbrt((double)n);
|
||||
return ((c * c * c) == n);
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
long n = 1;
|
||||
int squareOnlyCount = 0;
|
||||
int squareCubeCount = 0;
|
||||
while ((squareOnlyCount < 30) || (squareCubeCount < 3)) {
|
||||
long sq = n * n;
|
||||
if (isPerfectCube(sq)) {
|
||||
squareCubeCount++;
|
||||
System.out.println("Square and cube: " + sq);
|
||||
}
|
||||
else {
|
||||
squareOnlyCount++;
|
||||
System.out.println("Square: " + sq);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue