Answer:
For challenge 1:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Get an integer from the keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = scanner.nextInt();
// Print all the factors of the integer
System.out.print("Factors of " + num + " >>> ");
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
System.out.print(i + " ");
}
}
}
}
For challenge 2:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Get an integer from the keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = scanner.nextInt();
// Count the number of cool numbers from 1 to n
int coolCount = 0;
for (int i = 1; i <= n; i++) {
if (i % 3 == 1 && i % 4 == 1 && i % 5 == 1 && i % 6 == 1) {
coolCount++;
}
}
// Print the result using concatenation
System.out.println("There are " + coolCount + " cool numbers up to " + n);
}
}
For challenge 3:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Get an integer from the keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = scanner.nextInt();
// Count the number of cool numbers from 1 to n using a while loop
int coolCount = 0;
int i = 1;
while (i <= n) {
if (i % 3 == 1 && i % 4 == 1 && i % 5 == 1 && i % 6 == 1) {
coolCount++;
}
i++;
}
// Print the result using concatenation
System.out.println("There are " + coolCount + " cool numbers up to " + n);
}
}
For challenge 5:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Get an integer from the keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = scanner.nextInt();
// Determine if the integer is a perfect number
int sum = 0;
for (int i = 1; i < num; i++) {
if (num % i == 0) {
sum += i;
}
}
if (sum == num) {
System.out.println(num + " is a perfect number.");
} else {
System.out.println(num + " is not a perfect number.");
}
}
}
For challenge 6:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Get an integer from the keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = scanner.nextInt();
// Determine if the integer is a perfect number using a do-while loop
int sum = 0;
int i = 1;
do {
if (num % i == 0) {
sum += i;
}
i++;
} while (i < num);
if (sum == num) {
System.out.println(num + " is a perfect number.");
} else {
System.out.println(num + " is not a perfect number.");
}
}
}