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
8.5k points

Related questions

asked Feb 6, 2024 224k views
Alex Ponomarev asked Feb 6, 2024
by Alex Ponomarev
8.3k points
1 answer
4 votes
224k views
asked Dec 26, 2024 78.2k views
Kichu asked Dec 26, 2024
by Kichu
7.8k points
2 answers
1 vote
78.2k views
asked Nov 12, 2024 136k views
Foobarbecue asked Nov 12, 2024
by Foobarbecue
8.6k points
1 answer
4 votes
136k views