Write your code in the file LuckySevensjava Use the 10 modul
Write your code in the file LuckySevens.java Use the 10 module for alt 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).
Solution
LuckySevens.java
import java.util.Scanner;
public class LuckySevens {
public static void main(String s[]){
Scanner scan = new Scanner(System.in);
System.out.print(\"The lower end of the range: \");
int lower = scan.nextInt();
System.out.print(\"The upper end of the range: \");
int upper = scan.nextInt();
int count = 0;
for(int i=lower; i<=upper; i++){
for(int j=i; j>0; j=j/10){
if(j % 10 == 7){
count++;
}
}
}
System.out.println(\"RESULT: \"+count);
}
}
Output:
The lower end of the range: 100
The upper end of the range: 150
RESULT: 5
