Problem Statement:
On the eve of the Silver Jubilee Celebrations of the college, the college management has decided to give Lucky Prizes for students whose enrolment numbers.
- does not contain any even digits
- does not start or end with 1
Given the enrollment number of a student, write a program to find whether the student is eligible for the lucky prize or not.
Input Format:Input consists of the enrollment number of the student.Output Format:
Output consists of a string that is either 'yes' or 'no'.Sample Input1:
Print 'yes' if the student is eligible and print 'no' otherwise.
379517
Sample Output1:
yes
Sample Input2:
1371
Sample Output2:
no
Sample Input3:
3234
Sample Output3:
no
Solution in | JAVA | PYTHON |
---|
import java.util.Scanner;
public class LuckyPrize{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int enrollNo = sc.nextInt();
String s = String.valueOf(enrollNo);
int flag = 0;
if(s.charAt(0)=='1' || s.charAt(s.length()-1)=='1'){
flag=1;
}else{
for(int i=0;i<s.length();i++){
if((int)s.charAt(i)%2==0){
flag=1;
break;
}
}
}
if(flag==0){
System.out.print("yes");
}else{
System.out.print("no");
}
}
}
public class LuckyPrize{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int enrollNo = sc.nextInt();
String s = String.valueOf(enrollNo);
int flag = 0;
if(s.charAt(0)=='1' || s.charAt(s.length()-1)=='1'){
flag=1;
}else{
for(int i=0;i<s.length();i++){
if((int)s.charAt(i)%2==0){
flag=1;
break;
}
}
}
if(flag==0){
System.out.print("yes");
}else{
System.out.print("no");
}
}
}