Write a program to find out whether the given number is a perfect cube or not

Chikul
Posted by Chikul under Others category on | Views : 12911
For e.g.
Scenario 1: Input = 24 Output = 24 is not a perfect cube
Scenario 2: Input = 27 Output = 27 is a perfect cube of 3

import java.io.*;
import java.lang.*;

public class PerfectCube
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a no : ");

int i=Integer.parseInt(br.readLine());
int j,k,c1=0;
j=i/2;
int c=0;
for(k=2;k<=j;k++)
{
if(i%k==0)
{
//System.out.println(k);
if((k*k*k)==i)
{
c1=1;
}
}
}
if(c1==1)
{
System.out.println("Perfect CUBE");
}
else
{
System.out.println("Not a Perfect CUBE");
}
}
}

Comments or Responses

Posted by: Santosh4u on: 12/23/2009 Level:Bronze | Status: [Member]
Nice Code.

Login to post response