Program name ModProgjava Problem definition define three int

Program name   ModProg.java

   Problem definition:

define three ints

int start;

int end;

int divisor;

Prompt the user for a ‘start’ number

Prompt the user for a ‘end’ number

Prompt the user for a ‘divisor’ number

find all the numbers between start and end that are

evenly divisible by divisor

   Output should look like:

       The following numbers

   between start and end

   are divisible by divisor

           nn

           nn

           etc

where start, end, and divisor are the three numbers obtained from the user.

   Use a post-test loop for this project.

Solution

ModProg.java

import java.util.Scanner;


public class ModProg {
   public static void main(String[] args) {
       int start;
       int end;
       int divisor;
       Scanner scan = new Scanner(System.in);
       System.out.println(\"Enter the start number: \");
       start = scan.nextInt();
       System.out.println(\"Enter the end number: \");
       end = scan.nextInt();
       System.out.println(\"Enter the divisor number: \");
       divisor = scan.nextInt();

       System.out.println(\"The following numbers between start and end are divisible by divisor\");
       for(int i=start; i<=end; i++){
           if(i % divisor == 0){
               System.out.println(i);
           }
       }
      
   }
}

Output:

Enter the start number:
1
Enter the end number:
100
Enter the divisor number:
5
The following numbers between start and end are divisible by divisor
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100

Program name ModProg.java Problem definition: define three ints int start; int end; int divisor; Prompt the user for a ‘start’ number Prompt the user for a ‘end
Program name ModProg.java Problem definition: define three ints int start; int end; int divisor; Prompt the user for a ‘start’ number Prompt the user for a ‘end

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site