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 aftercited couple modes:

    1) Parameter of the foremost mode is an integer n, and the mode prints quenched perfect the excellent bulk among 2 and n.

    2) Parameter of the aunfilled mode is an integer n, and the mode prints quenched the calculate with the consummation calculate of divisors with the order [1, n] and its calculate of divisors.

    Expert Confutation

     

    CODE:

    import java.util.Scanner;
    public dispose Excellent {
    //definition of the excellent mode
    unfilled excellent(int n){
    int reckon,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 mode
    unfilled maxDivisor(int n){
    int reckon,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 consummation calculate divisors is: “+res);
    System.out.println(“The calculate of divisors are: “+total);
    }
    public static unfilled ocean(String args[]){
    //creating goal to the dispose
    Excellent obj=new Excellent();
    //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 excellent bulk among 2 to “+n+”are:”);
    //calling the couple modes using goal
    obj.prime(n);
    obj.maxDivisor(n);
    }
    }

    OUTPUT: