CHECKING THAT NUMBER IS SUNNY OR NOT IN JAVA
package mypro;
import java.util.Scanner;
public class SunnyNumBetRange {
public static void main(String[] args) {
System.out.println("Enter the range r1 and r2 to check all the number they are sunny or not ");
Scanner obj = new Scanner(System.in);
int r1 = obj.nextInt();
int r2 = obj.nextInt();
for(int i=r1; i<=r2; i++) {
int n=i,rem ,nsq=i*i,add=0;
while(nsq>0) {
rem=nsq%10;
add=add+rem;
nsq=nsq/10;
}
if(add==n) {
System.out.println("The number "+ n+" sunny");
}
else {
System.out.println("The number "+ n+" is not sunny");}
}
}
}
Comments
Post a Comment