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:

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

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 numbe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site