wulev

Java - Methods - Loops - Homework-Symmetric Numbers in Range

May 30th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. /*Write a program to generate and print all symmetric numbers in given range [start…end] (0 ≤ start ≤ end ≤ 999). A number is symmetric if its digits are symmetric toward its middle. For example, the numbers 101, 33, 989 and 5 are symmetric, but 102, 34 and 997 are not symmetric.
  2. import java.util.Scanner;*/
  3.  
  4.  
  5. public class _01_SymmetricNumbersInRange {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Scanner input = new Scanner(System.in);
  10.         int start = input.nextInt();
  11.         int end = input.nextInt();
  12.        
  13.         for (int i = start; i <= end; i++) {
  14.             if (i > 0 && i < 10) {
  15.                 System.out.println(i);
  16.             }
  17.             else {
  18.                 if (i%10 == i/10 || i%10 == i/100) {
  19.                     System.out.println(i);                 
  20.                 }
  21.             }
  22.         }
  23.  
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment