Advertisement
dimipan80

Numbers in Interval Dividable by Given Number

Aug 6th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /* Write a program that reads two positive integer numbers and prints how many numbers p
  2.  * exist between them such that the reminder of the division by 5 is 0. */
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class NumbersInIntervalDividableBy5 {
  7.  
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Scanner scan = new Scanner(System.in);
  11.         System.out.print("Enter a positive Integer Number for Start: ");
  12.         int start = scan.nextInt();
  13.         System.out.print("Enter other positive Integer number, bigger from the First: ");
  14.         int end = scan.nextInt();
  15.         scan.close();
  16.  
  17.         if (start > 0 && end > start) {
  18.             int counter = 0;
  19.             for (int i = start; i <= end; i++) {
  20.                 if (i % 5 == 0) {
  21.                     counter++;
  22.                 }
  23.             }
  24.  
  25.             System.out.printf("In that Interval has %d numbers dividable by 5, without remainder!\n",
  26.                             counter);
  27.  
  28.         } else {
  29.             System.out.println("Error! - Wrong Input!!!");
  30.         }
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement