Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in java that initially displays all the numbers from 100 to 200

ID: 641846 • Letter: W

Question

Write a program in java that initially displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not by both. In your output you should only display ten numbers per line, or less if there are not another ten numbers left to display. Also, design the program such that it asks the user if they want to continue with a different lower limit and upper limit after each run, ending the program only when they do not respond to the question with "Yes" (case does not matter).

Here is a sample run:

Explanation / Answer

import java.util.Scanner;


public class Multiples {
  
   public static void print(int lim1, int lim2){
       System.out.println("Multiples of 5 or 6 (but not both) between " + lim1 + " and " + lim2 + ":");
       int itr = 0;
       for(int i = lim1; i <= lim2; ++i){
           if((i % 5 == 0 && i % 6 != 0) || (i % 5 != 0 && i % 6 == 0)){
               System.out.print(i + " ");
               if((itr + 1) % 10 == 0){
                   System.out.println();
               }
               itr++;
           }
       }
       System.out.println();
   }
  
   public static void main(String args[]){
       Scanner in = new Scanner(System.in);
       Scanner in2 = new Scanner(System.in);
       String option = "";
       int limit1 = 100;
       int limit2 = 200;
       while(true){
           print(limit1, limit2);
           System.out.print("Would you like different lower and upper limits? ");
           option = in2.nextLine();
           if(!option.equalsIgnoreCase("Yes")){
               break;
           }
           System.out.print("Lower limit? ");
           limit1 = in.nextInt();
           System.out.print("Upper limit? ");
           limit2 = in.nextInt();
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote