## Computer Science

A number is said to Bouncy number if the digits of the number are unsorted.

For example,

22344 - It is not a Bouncy number because the digits are sorted in ascending order.

774410 - It is not a Bouncy number because the digits are sorted in descending order.

155349 - It is a Bouncy number because the digits are unsorted.

A number below 100 can never be a Bouncy number.

Write a program in java to accept a number. Check and display whether it is a Bouncy number or not.

#### Java

#### Java Iterative Stmts

#### ICSE

4 Likes

### Answer

```
import java.util.Scanner;
public class KboatBouncyNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = in.nextInt();
if (n < 100) {
System.out.println(n + " is not a Bouncy Number.");
return;
}
int t = n;
boolean isIncreasing = true, isDecreasing = true;
int prev = t % 10;
while (t != 0) {
int d = t % 10;
if (d > prev) {
isIncreasing = false;
break;
}
prev = d;
t /= 10;
}
t = n;
prev = t % 10;
while (t != 0) {
int d = t % 10;
if (d < prev) {
isDecreasing = false;
break;
}
prev = d;
t /= 10;
}
if (!isIncreasing && !isDecreasing)
System.out.println(n + " is a Bouncy Number.");
else
System.out.println(n + " is not a Bouncy Number.");
}
}
```

### Output

Answered By

2 Likes

## Related Questions

Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100. Find the smallest integer that is greater than M and whose digits add up to N. For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add up to 11 is 119.

Write a program to accept the numbers M and N from the user and print the smallest required number whose sum of the digits is equal to N. Also, print the total number of digits present in the required number. The program should check for the validity of the inputs and display an appropriate message for an invalid input. Test your program with the sample data and some random data:

Example 1 Example 2 Input:

M = 100

N = 11Input:

M = 1500

N = 25Output:

The required number = 119

Total number of digits = 3Output:

The required number = 1699

Total number of digits = 4Example 3 Example 4 Input:

M = 99

N = 11Input:

M = 112

N = 130Output:

Invalid InputOutput:

Invalid InputAn Evil number is a positive whole number which has even number of 1's in its binary equivalent. Example: Binary equivalent of 9 is 1001, which contains even number of 1's. A few evil numbers are 3, 5, 6, 9…. Design a program to accept a positive whole number and find the binary equivalent of the number and count the number of 1's in it and display whether it is a Evil number or not with an appropriate message. Output the result in format given below:

Example 1

Input: 15

Binary Equivalent: 1111

No. of 1's: 4

Output: Evil NumberExample 2

Input: 26

Binary Equivalent: 11010

No. of 1's: 3

Output: Not an Evil NumberWrite a Program in Java to input a number and check whether it is a Fascinating Number or not.

Fascinating Numbers: Some numbers of 3 digits or more exhibit a very interesting property. The property is such that, when the number is multiplied by 2 and 3, and both these products are concatenated with the original number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes.

Let's understand the concept of Fascinating Number through the following example:

Consider the number 192

192 x 1 = 192

192 x 2 = 384

192 x 3 = 576

Concatenating the results: 192 384 576

It could be observed that '192384576' consists of all digits from 1 to 9 exactly once. Hence, it could be concluded that 192 is a Fascinating Number. Some examples of fascinating Numbers are: 192, 219, 273, 327, 1902, 1920, 2019 etc.Write a Program in Java to input a number and check whether it is a Pronic Number or Heteromecic Number or not.

Pronic Number: A Pronic number, oblong number, rectangular number or heteromecic number, is a number which is the product of two consecutive integers, that is, n (n + 1).

The first few Pronic numbers are:

0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.