[Solved] 3ple Newton’s Triwizard Contest with Java

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.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

πŸ“Œ Nodejs and Android 😎
πŸ“Œ Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *