Monday, January 23, 2017

// // 1 comment

Exercise 3.12 — Check a Number

Java program that prompts the user to enter an integer and checks whether the number is divisible by both 5 and 6, or neither of them, or just one of them.

/**
 *
 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 */

import java.util.Scanner;

public class Ex03_12 {
    public static void main(String[] args) {
        int num;
        Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer: ");
        num = input.nextInt();
        if (num % 5 == 0 && num % 6 == 0) {
            System.out.println(num + " is divisible by both 5 and 6");
        } else if (num % 5 == 0 || num % 6 == 0) {
            System.out.println(num + " is divisible by 5 or 6, but not both");
        } else {
            System.out.println(num + " is not divisible by either 5 or 6");
        }
    }
}
Liang Introduction to Java Programming exercise 3.12 solution
Sample program run
Click here to see other solutions to Introduction to Java Programming.

1 comment:

  1. This is just what I need to familiarize myself in this field. Looking forward to many interesting and helpful articles from you. the article is very interesting and effective.

    Fast dedicated server

    ReplyDelete


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.

Thanks.