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)
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();
}}
Comments
Leave a comment