0% found this document useful (0 votes)
21 views1 page

Sandwich Number

Uploaded by

abdullahtaha206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Sandwich Number

Uploaded by

abdullahtaha206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Class Sandwich_Number - Neel's Java Programs 1/1

import java.util.*;
class Sandwich_Number // A number whose one more is a perfect square and one
less is a perfect cube
{
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a number");
int n=in.nextInt();
int a=(int)Math.sqrt(n-1);
int b=(int)Math.cbrt(n+1);
if(a*a==(n-1) && b*b*b==(n+1))
System.out.println("Sandwich Number");
else
System.out.println("Not a Sandwich Number");
}
}

6 Feb, 2023 7:09:48 PM

You might also like