Skip to content

Commit 34ab99f

Browse files
Solution for Keprekar Number
1 parent 3b28ad9 commit 34ab99f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"java.project.sourcePaths": [
3+
"Basic Codes",
4+
"Number Theory"
5+
]
6+
}

Number Theory/KeprekarNo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//Write a program to check if a number is Special or not
2+
import java.util.*;
3+
class Keprekar{
4+
public static void main(String args[]){
5+
Scanner sc=new Scanner(System.in);
6+
System.out.println("Enter any number"); //Input number from the user
7+
int n=sc.nextInt();
8+
9+
String s=String.valueOf(n);
10+
int l=s.length();
11+
int sq=n*n;
12+
int sum=(sq/(int)(Math.pow(10,l)))+(sq%(int)(Math.pow(10,l))); // Find the sum of the two divided parts of the number
13+
if(sum==n){ // Compare whether the sum is equal to the number or not
14+
System.out.println(n+" is a Keprekar Number");
15+
}
16+
else{
17+
System.out.println(n+" is not a Keprekar Number");
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)