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

Write a complete java program, called MyProgram, thet has the following properti

ID: 3683813 • Letter: W

Question

Write a complete java program, called MyProgram, thet has the following properties: A methed, called computeSum, thet receives 2 integer values, say A and B, and returns the sum of all values between A and B (including A and B). A must be less then B for the methed to return the sum. Otherwise the methed returns 0. No printing inside the methed. A methed, called isPrime, thet receives the sum and determines if the sum is a prime number by returning true if the number is prime and false if the number is not prime. No printing inside the methed. Sample Runs Enter 2 numbers: 2 4 Output is 9 9 is not a prime number

Explanation / Answer

/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       int a,b;
       a = 2;
       b = 4;
      
       System.out.println("Enter 2 numbers: ");
       Scanner scan = new Scanner(System.in);
       a = scan.nextInt();
       b = scan.nextInt();
      
       System.out.println("You entered "+a+" and "+b);
       int sum = computeSum(a, b);
       System.out.println("Output is "+sum);
       if(isPrime(sum))
           System.out.println(sum+" is a Prime number");
       else
           System.out.println(sum+" is not a Prime number");
   }
  
   public static int computeSum(int a, int b)
   {
       int i,sum=0;
      
       if(b<a)
           return 0;
          
       for(i=a;i<=b;i++)
           sum += i;
      
       return sum;
   }
  
   public static boolean isPrime(int a)
   {
       int i, total = 0;
      
       if(a==0)
       return false;
      
       for(i=1;i<=a;i++)
           if(a%i==0)
               total += 1;
              
       if(total==2)
           return true;
       else
           return false;
   }

}

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