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

Write an JAVA Method. Write a method called numRemainderMatches which retruns an

ID: 659964 • Letter: W

Question

Write an JAVA Method.

Write a method called numRemainderMatches which retruns an int, takes an array of integers as its first parameter and a single positive digit (int) as its second parameter.  It looks at the last digit of each number in the array and compares it to the digit passed in as the second parameter.  It returns an int corresponding to the number of matches it found doing this comparison.  So, for example, if we passed in the array:  [29, 934, 3, 64, 12, 92, 7] and the digit: 4, it would compare the last digit of 29 (9) to 4, and those don't match, then the last digit of 934 (4) to 4, and those do match, then the last digit of 3 (3) to 4, and those don't match, then the last didfit of 64 (4) to 4, and those do match, then the last digit of 12 (2) to 4, and those don't match, then the last digit of 92 (2) to 4, and those don't match, and finally the last digit of 7 (7) to 4, and those don't match, so we found 2 matches to 4 (934 and 64), so we would return 2 if those were the array and digit passed in.  You code needs to work for any array of ints and any single positive digit int passed in.  The way to get the last digit of a number is by taking the remainder after dividing each element of the array by 10.  Use the % operator to get this remainder.

Explanation / Answer

import java.util.*;

class Reminder
{
   int a[]=new int[5]; // array declaration
   int count=0,n;
    Scanner sr= new Scanner(System.in);
   
       public void numRemainderMatches(){

       System.out.println("Enter digit to n:");
       int len = a.length();
       System.out.println("Lenngth of array:"+len);
       for(int i=0;i<=len; i++)
       {
          int lastDigit =a[i]%10;
          if(lastDigit==n){
              count++;
              return count;
       }else {
       //System.out.println("Digit not matched");
       return 0;
       }
  
   }
   public static void main(String[] args)
   {
//       System.out.println("Hello World!");
      Reminder r= new Reminder();

       n=sr.nextInt();

       r.numRemainderMatches(n);

     
   }
}

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