You are currently viewing Interview Program

Interview Program

Print all jumping numbers smaller than or equal to x.

Input: x = 105
Output: 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101

Note: A number is called as a jumping number if all adjacent digits in it differ by 1. The difference between ‘9’ and ‘0’ is not considered as 1.





public class JumpingNumber {

	public static boolean jumpingNumer(int num) {
		while (num > 9) {
			int diff = num % 10;
			num = num / 10;
			int diff1 = num % 10;
			if (Math.abs(diff - diff1) != 1)
				return false;

		}
		return true;
	}

	public static void main(String[] args) {

		int n = 105;
		for (int i = 0; i <= n; i++) {
			if (jumpingNumer(i)) {
				System.out.print(i + " ");
			}
		}

	}

}

Thanks and Regards,
Solution provided by Nilmani Prashanth

Our Best Partners: https://vironlisenssikasinot.com/ https://crazytime-bangladesh.com/ https://luckyjetslots.com/ru/ google play card casino uudet kasinot ilman kierrätystä kasino nopea kotiutus pg soft games fortune ox https://crazytime-tracker.com/tracker/ lucky jet 1win apk download online casino echtgeld google pay

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply