Answer to Question #266285 in Java | JSP | JSF for Michael

Question #266285

Write a program in java to take a number as input then display highest even factors the number has using method prototype: int highest(int n)


1
Expert's answer
2021-11-15T17:28:26-0500
import java.util.Scanner;
public class Main {
  static void highest(){
  Scanner input=new Scanner(System.in);
    int n = input.nextInt();


    System.out.print("Highest even Factors of " + n + " are: ");
    for (int i = 1; i <= n; ++i) {
        
      if (n % i == 0&&i%2==0) {
        System.out.print(i + " ");
      }
    }
  }
public static void main(String[] args) {
    
    highest();
}}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS