Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
To check whether a given number is smith number or not
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter a number"); int n=sc.nextInt();int s=0,d,e=0; for(int i=n;i>1;) { for(int j=2;j<=i;j++) { if(i%j==0) { i=i/j; for(int l=j;l>0;l=l/10) { d=l%10; s=s+d; } break; } } } for(int m=n;m>0;m=m/10) e=e+(m%10); if(s==e) System.out.println("Smith number"); else System.out.println("Not a smith number"); } }
run
|
edit
|
history
|
help
0
Ways to form Max Heap
MergeSort
Daugybos lentele
smallest number and its index(position)
Решето Эратосфена
PE #9
Product of Array Except Self
names
Interference
Кошачья бойня