138k views
5 votes
HEYYY! I NEED HELP! CAN SOMEONE WRITE A PROGRAM FOR ME PLEASE?? INSTRUCTIONS ARE BELOW!! OMG IT WOULD MEAN THE WORLD TO ME!!

Write a program that will allow the user to input a positive integer (zero is not included)
Validate that the input value is a positive integer
Calculate and print out all of the factors of the input integer
Example Output

Enter a positive integer: -10

Invalid entry. Number must be positive.

Enter a positive integer: 48

The factors of 48 are 1, 2, 3, 4, 6, 8, 12, 16, 24, and 48

1 Answer

3 votes

Answer:

Required program in Java language

public class Main {

public static void main(String[] args) {

// positive number

int number = 60;

System.out.print("Factors of " + number + " are: ");

// loop runs from 1 to 60

for (int i = 1; i <= number; ++i) {

// if number is divided by i

// i is the factor

if (number % i == 0) {

System.out.print(i + " ");

}

}

}

}

Hope it helps

User Bbx
by
4.0k points