From 3e1377916f87df0b6a73a1306622bf8e46a0c29c Mon Sep 17 00:00:00 2001 From: 101zh <67253838+101zh@users.noreply.github.com> Date: Fri, 27 Oct 2023 23:39:57 +0000 Subject: [PATCH] feat(4.3.4): Finish U4_L3_Activity_Four --- src/main/java/Unit4/U4_L3_Activity_Four.java | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/Unit4/U4_L3_Activity_Four.java diff --git a/src/main/java/Unit4/U4_L3_Activity_Four.java b/src/main/java/Unit4/U4_L3_Activity_Four.java new file mode 100644 index 0000000..7ececd4 --- /dev/null +++ b/src/main/java/Unit4/U4_L3_Activity_Four.java @@ -0,0 +1,42 @@ +package Unit4; + +import java.util.Scanner; + +public class U4_L3_Activity_Four { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter a positive integer:"); + int num = scanner.nextInt(); + + if (num > 0) { + for (int i = num; i >= 0; i--) { + if (i % 3 == 0) { + System.out.print(i + " "); + } + } + } else { + System.out.println("error"); + } + + scanner.close(); + } + + public static void alternateAnswer(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter a positive integer:"); + int num = scanner.nextInt(); + num = num - (num % 3); + + if (num > 0) { + for (int i = num; i >= 0; i -= 3) { + System.out.print(i + " "); + } + } else { + System.out.println("error"); + } + + scanner.close(); + } +}