https://www.codechef.com/FXBG2020/problems/FTB002

https://www.codechef.com/FXBG2020/problems/FTB002
Author:-pj220593
Tester:-pj220593
Difficulty:-Easy
Prerequisites:-If-Else
Solution:-
The approach of this problem is to check the number from backwards. The number, if does not contain one of the three prescribed numbers 2,27,277 will not be special number and hence the output will be “NO”.
import java.util.;
import java.lang.
;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try{
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
boolean flag=true;
while(n>0)
{
if(n%1000==277)
{
n=n/1000;
}
else if(n%100==27)
{
n=n/100;
}
else if(n%10==2)
{
n=n/10;
}
else
{
flag=false;
break;
}
}
if(flag)
System.out.println(“YES”);
else
System.out.println(“NO”);
}catch(Exception e){}
}

}