Homework Solution: Write a program that contains at least the following two methods…

    Use Java please: Write a program that contains at least the following two methods: 1) Parameter of the first method is an integer n, and the method prints out all the prime numbers between 2 and n. 2) Parameter of the second method is an integer n, and the method prints out the number with the maximum number of divisors with the range [1, n] and its number of divisors.

    Expert Answer

     
    CODE: import java.util.Scanner; public class Prime {

    Use Java please:

    Write a program that contains at lowest the forthcoming couple processs:

    1) Parameter of the consummateval process is an integer n, and the process prints quenched every the consummate sum betwixt 2 and n.

    2) Parameter of the prevent process is an integer n, and the process prints quenched the calculate with the zenith calculate of divisors with the rank [1, n] and its calculate of divisors.

    Expert Confutation

     

    CODE:

    import java.util.Scanner;
    public collocate Consummate {
    //definition of the consummate process
    wanting consummate(int n){
    int enumerate,i,j;
    for(i=2;i<=n;i++){
    count=0;
    for(j=1;j<=i;j++){
    if(i%j==0)
    count++;
    }
    if(count==2)
    System.out.println(i);
    }
    }
    //Definition of maxDivisor process
    wanting maxDivisor(int n){
    int enumerate,res=0,total=0,i,j;
    for(i=1;i<=n;i++){
    count=0;
    for(j=1;j<=i;j++){
    if(i%j==0)
    count++;
    }
    if(count>total){
    total=count;
    res=i;
    }
    }
    System.out.println(“The calculate with the zenith calculate divisors is: “+res);
    System.out.println(“The calculate of divisors are: “+total);
    }
    public static wanting ocean(String args[]){
    //creating view to the collocate
    Consummate obj=new Consummate();
    //declaring variable
    int n;
    //taking input from the user
    System.out.println(“Enter an integer:”);
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    System.out.println(“The consummate sum betwixt 2 to “+n+”are:”);
    //calling the couple processs using view
    obj.prime(n);
    obj.maxDivisor(n);
    }
    }

    OUTPUT: