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

Given this program: mport java.util.Scanner; public class Bootcamp { public stat

ID: 651748 • Letter: G

Question

Given this program:

mport java.util.Scanner;

public class Bootcamp {

       public static void main(String[] args) {

              int a;

              int b;

              Scanner in = new Scanner(System.in);

              System.out.println("Ebter the integer range as 1 to 1000");

              System.out.println("Enter your first integer:");

              a = in.nextInt();

              System.out.println("Enter your second integer:");

              b = in.nextInt();

              System.out.println("The Result is:");

              if(a > 0 && b < 1001) {

                     for (int i=a; i<b; i++) {

                           if (i % 5 != 0 && i % 7 != 0) {

                                  System.out.print(i +" ");

                           }

                     }

              }

             

              else{

                     System.out.print("Enter the range as 1 to 1000");

              }

       }

}

Add a method to ScanData that will only accept ODD integers between a low and high value.

Example usuage in main:

int x = ScanData.getOddInt(1,10,

Explanation / Answer

Here's the method.

comment if you have any doubts.

public static int getOddInt(int min, int max, String display)
   {
       Scanner in = new Scanner(System.in);
       System.out.println(display);
       int number=in.nextInt();
       in.nextLine();
       if(number%2!=0)
       {
           if(number>=min && number<=max)
               return number;
           else
           {
               System.out.println("Number out of bounds!");
               return getOddInt(min, max, display);
           }
       }
       else
       {
           System.out.println("Not an Odd number!");
           return getOddInt(min, max, display);
       }
   }

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