You are given a positive integer N. Print “Yes” if N is a multiple of 3, otherwise print “No”.
Input
The input consists of a single integer N.
Constraints:
1 ≤ N ≤ 1000
Output
If N is a multiple of 3, print “Yes”. Otherwise, print “No” (without the quotation marks). Note that the output is case-sensitive.
Example
Sample Input 1:
6
Sample Output 1:
Yes
Sample Input 2:
10
Sample Output 2:
No
Solution
Approach: The problem is simple. If the number is divisible by 3, then it is a multiple of 3. Otherwise, it is not a multiple of 3.
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n % 3 == 0) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}Happy Learning – If you require any further information, feel free to contact me.
![[Solved] 3ple Newton's Triwizard Contest with Java [Solved] 3ple Newton's Triwizard Contest with Java](https://realcoder.techss24.com/wp-content/uploads/2022/11/Solved-3ple-Newtons-Triwizard-Contest-with-Java.png)
![[Solved] Wildcard Matching with Java, C++, Python](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Wildcard-Matching-with-Java-C-Python-300x200.png)
![[Solved] Casper at the Carnival with Python, C++, Java, C](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Casper-at-the-Carnival-with-Python-C-Java-C-300x200.png)
![[Solved] Recursion Factorial with Java](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Recursion-Factorial-with-Java-300x200.png)