Write your code in the file LuckySevensjava Use the IO modul
Write your code in the file LuckySevens.java. Use the IO module for all inputs and outputs. Sevens are considered lucky numbers. Your task is to count the number of sevens that appear within a range of numbers. Your solution should make use of looping constructs. Ask the user for the following information, in this order: The lower end of the range The upper end of the range Determine the number of sevens that appear in the sequence from lower end to upper end (inclusive). Hint: Some numbers have more than 1 seven, and not every 7 appears in the ones place. Hint2: Nested loops are helpful
Exit on error.
Example:
Thank you in advance
Solution
Here is the code for you:
import java.util.*;
class LuckySevens
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print(\"Enter the lower end of the range: \");
int low = sc.nextInt();
System.out.print(\"Enter the upper end of the range: \");
int high = sc.nextInt();
int countSevens = 0;
for(int i = low; i <= high; i++)
{
int temp = i;
while(temp != 0)
{
int digit = temp % 10;
if(digit == 7)
countSevens++;
temp /= 10;
}
}
System.out.println(\"The number of sevens in the specified range is: \" + countSevens);
}
}
