-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from shreeyachatzz/patch-8
Create Diasarium.java
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Program's_Contributed_By_Contributors/Java_Programs/Diasarium.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//coded by shreeyachatzz | ||
//To check if a number is diasrium or not | ||
import java.util.*; | ||
public class dias | ||
{ | ||
//To find the sum of the digits raised to the power of their positional value present in the number'num' | ||
int sumofsq( int num) | ||
{ | ||
int s= 0; int f=0; | ||
for( int i= num; i>0; i=i/10)//counting the number of digits | ||
{ | ||
f=f+1; | ||
} | ||
for( int i= num; i>0; i=i/10)//To find sum of the digits raised to the power of their positional value | ||
{ | ||
int p = i%10; | ||
s=s+(int)(Math.pow(p,f)); | ||
f=f-1;//Decrementing the positional value with each iteration | ||
} | ||
return(s); | ||
} | ||
|
||
void checkdias(int num)//To prnt the final result | ||
{ | ||
if((sumofsq(num))==num) | ||
{ | ||
System.out.println("The Number Is Diasarium !!"); | ||
} | ||
|
||
else | ||
{ | ||
System.out.println("The Number Is NOT Diasarium !!"); | ||
} | ||
} | ||
|
||
public static void main ()//Main method | ||
{ | ||
Scanner sc= new Scanner (System.in); | ||
int n; | ||
System.out.println("Enter the number:");//Accepting number from user | ||
n= sc.nextInt(); | ||
dias ob= new dias();//Creating object | ||
ob.checkdias(n); | ||
} | ||
} | ||
/* | ||
(1)Enter the number: | ||
135 | ||
The Number Is Diasarium !! | ||
*//* | ||
(2)Enter the number: | ||
56 | ||
The Number Is NOT Diasarium !! | ||
*/ | ||
|