Skip to content

Commit

Permalink
Merge pull request #344 from shreeyachatzz/patch-8
Browse files Browse the repository at this point in the history
Create Diasarium.java
  • Loading branch information
fineanmol authored Oct 2, 2021
2 parents 61cde69 + fad0cbe commit bcc2874
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Program's_Contributed_By_Contributors/Java_Programs/Diasarium.java
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 !!
*/

0 comments on commit bcc2874

Please sign in to comment.