Hello! Tell me about the code?
Display all positive divisors of a natural number and count the number of divisors entered by the user from the keyboard.
The code seems to be running compiled.
1) Is the code correct for the positive dividers?
2) When compiled code displays the following:
Enter your natural number - 6 // entered number
The number 3 is divided by - 1 3 6 The number of dividers - 3
How can I make it so:
Enter your natural number - 6 // entered number
The number 3 is divided by - 1 3 6
The number of dividers - 3
How can you make the dividers appear in reverse order:
Enter your natural number - 6 // entered number
The number 3 is divided by - 6 3 1
The number of dividers - 3
3) How can the code be described, on an error, if the user entered a negative number?
4) How can the code be described, what cannot be divided into zero if the user entered 0?
public class Test { public static void main(String args[]){ int n; int count = 0; System.out.print("Вводите ваше натуральное число - "); Scanner sr = new Scanner(System.in); n = sr.nextInt(); System.out.print("Число " + n + " делится на - " ); for(int i = 1; i <= n; i++){ if ((n % i) == 0){ count++; System.out.print(i + " "); } } System.out.println("Количество делителей - " + count); } }