Skip to content

Commit

Permalink
feat(4.3.4): Finish U4_L3_Activity_Four
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Oct 27, 2023
1 parent a4859d4 commit 3e13779
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/Unit4/U4_L3_Activity_Four.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 3e13779

Please sign in to comment.