CoineTre

JF-ExcBasic02. Division

Jan 14th, 2021 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /*You will be given an integer and you have to print on the console whether that number is divisible by the following numbers: 2, 3, 6, 7, 10. You should always take the bigger division. If the number is divisible by both 2 and 3 it is also divisible by 6 and you should print only the division by 6. If a number is divisible by 2 it is sometimes also divisible by 10 and you should print the division by 10. If the number is not divisible by any of the given numbers print โ€œNot divisibleโ€. Otherwise print "The number is divisible by {number}".
  2. */
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Ex2Division {
  7.     public static void main(String[] args) {
  8.         int n = new Scanner(System.in).nextInt();
  9.         if (n%10==0){
  10.             System.out.println("The number is divisible by 10");
  11.         }else if (n%7==0){
  12.             System.out.println("The number is divisible by 7");
  13.         }else if (n%6==0){
  14.             System.out.println("The number is divisible by 6");
  15.         }else if (n%3==0){
  16.             System.out.println("The number is divisible by 3");
  17.         }else if (n%2==0){
  18.             System.out.println("The number is divisible by 2");
  19.         }else{
  20.             System.out.println("Not divisible");
  21.         }
  22.     }
  23. }
Add Comment
Please, Sign In to add comment