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

can someone solve it Write the following methods in a Java project: b) A Java me

ID: 667520 • Letter: C

Question

can someone solve it

Write the following methods in a Java project:

b) A Java method to determine and return the sum of last N numbers, where N and the

numbers are in an array of a length greater or equal to N are all received as parameters.

c) A Java method to determine and return an appropriate value indicating if a number N is even

or odd, where N is received as a parameter.

d) A Java method to determine and return an appropriate value indicating if a word is present in

a file, where the filename and word is received as parameters.

e) Test the above methods from the main method

Explanation / Answer

import java.lang.*;
import java.io.*;


class Ideone{
   // b part
   public static void first(int[] l, int n){
       if (l.length < n){
           System.out.println("Array Must have n integers");
       }
       int sum = 0;
       int i = 0;
       while(i < n){
           sum += l[l.length-1-i];
           i++;
       }
       return sum;
   }
   // c part
   public static boolean odd_even(int n){
       if (n % 2 == 0) return true;
       return false;
   }
   // d part
   public static boolean in_it(String filename,String word){
       BufferedReader br = null;
       try {
           String sCurrentLine;
           br = new BufferedReader(new FileReader(filename));
           while ((sCurrentLine = br.readLine()) != null) {
               String[] temp = sCurrentLine.split(" ");
               for (int i = 0; i < temp.length; i++){
                   if (temp[i].compareTo(word) == 0)
                       return true;
               }
           }
           return false;

       }
       catch (IOException e) {
           e.printStackTrace();
       }

   }
   public static void main (String[] args){{
      
   }
}

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