[Solved] Lucky Numbers STARTERS 73 CodeChef

Chef calls a number lucky if it contains the digit 77 at least once.

Given a number XX, determine if it is a lucky number or not.

Input Format
  • The first line contains a single integer TT — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains an integer XX — the number mentioned in the problem statement.
Output Format

For each test case, output YES if XX is a lucky number. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yesyEsYes will be considered identical).

Constraints
  • 1 ≤T≤1000
  • 1 ≤X≤10^9

Sample 1:

Input:

4
6
478
2090
77777

Output:

NO
YES
NO
YES
Explanation:

Test Case 1: The number 66 is not lucky since it does not contain the digit 77.

Test Case 2: The number 478478 is lucky since it contains the digit 77 at least once.

Test Case 3: The number 20902090 is not lucky since it does not contain the digit 77.

Test Case 4: The number 7777777777 is lucky since it contains the digit 77 at least once.

Solution

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{

    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            String s = Integer.toString(n);
            if(s.contains("7")){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *