Spy number in java

preview_player
Показать описание
#teclearners #java #icse
Spy number is a number
if the sum of its digits equal the product of its digits.
Example 1124
1+1+2+4 = 8
1*1*2*4 = 8
Logic
Input number
Extract digits of number
find sum of digits
find product of digits
compare sum and product
Display result
Рекомендации по теме
Комментарии
Автор

Thanks from heart ❤ easy explanation..😊

sumanshukla
Автор

package com.naveen;

import java.util.Scanner;

public class fetch {
public static void main(String[] args) {

int no =217;
int sum = 0;

int po1 =no;
while(po1 != 0){
int rem1 = po1%10;
sum = sum+rem1;
po1/=10;
}
System.out.println(sum);

int pro = 1;
int po2 = no;
while(po2 != 0){
int rem2 = po2%10;
pro = pro*rem2;
po2/=10;
}
System.out.println(pro);
if(sum == pro){
System.out.println("spy");
}
else{
System.out.println("not a spy");
}
}

}

makineninaveen