Question: You will write a program with two methods that will determine how many individual digits in an integer are between 3 and 6 (inclusive). Instructions:

You will write a program with two methods that will determine how many individual digits in an integer are between 3 and 6 (inclusive). Instructions: Create a project and a class named DigitCount in BlueJ.

Add an import java.util.*; statement before the class and create a main program inside the class.

In the main program, do the following: o Create a Scanner object that will be used for user input. o Prompt the user to enter an integer and store the value in a variable named num. o Call a method named getCount (details are given below) that will return the number of individual digits in the number that are between 3 and 6 (inclusive). o Display the original number and the number of digits between 3 and 6.

Create the method getCount that has a parameter of type int and returns a value of type int. This method will do the following: o Declare an integer variable named count and initialize it to 0. o Within a while or do-while loop, do the following: Get the last digit of the parameter by getting the remainder after dividing by 10. Use the % operator to do this. Call the inRange method, passing this digit as a parameter. If the inRange method returns true, add 1 to count. Use integer division by 10 on the parameter to change its value by getting rid of the last digit. Use the / operator to do this. o Stay in the loop as long as the parameter is greater than 0.

Create the method inRange that has a parameter of type int and returns a value of type Boolean. This method will return true if the parameter is between 3 and 6 (inclusive).

---------

This is what I have so far, any help?

import java.util.*; public class DigitCount { public static void main(String[] args){ int count = 0; Scanner kb = new Scanner (System.in); System.out.print("Enter an integer please: "); int num = kb.nextInt(); System.out.print("Your number is " + num); }//end main public static int getCount(int n){ int num = 0; while (n !=0) { n = n/10; ++num; } return num; }//end while public static boolean inRange(int n) { return (n >= 3 && n <= 6); }//boolean }//end getCount

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!