Affluent Savvy
Photo by Zac Frith Pexels Logo Photo: Zac Frith

What are the unique numbers?

The number will be unique if it is positive integer and there are no repeated digits in the number. In other words, a number is said to be unique if and only if the digits are not duplicate. For example, 20, 56, 9863, 145, etc. are the unique numbers while 33, 121, 900, 1010, etc.

What is Aquarius BFF?
What is Aquarius BFF?

Aquarius Compatibility – Best Friend Match with Aries, Gemini, Libra & Sagittarius.

Read More »
How to know if I'm rich?
How to know if I'm rich?

How much money do you need to be considered rich? According to Schwab's 2022 Modern Wealth Survey (opens in new tab), Americans believe it takes an...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

next → ← prev Unique Number in Java Program The number will be unique if it is positive integer and there are no repeated digits in the number. In other words, a number is said to be unique if and only if the digits are not duplicate. For example, 20, 56, 9863, 145, etc. are the unique numbers while 33, 121, 900, 1010, etc. are not unique numbers. In this section, we will create Java programs to check whether the number is unique or not. There are the following ways to check the number is unique or not: By Comparing Each Digit Manually

Using String

Using Array By Comparing Each Digit Manually There are the following steps to check number is unique or not: Read a number from the user. Find the last digit o the number. Compare all digits of the number with the last digit. If the digit found more than one time, the number is not unique. Else, eliminate the last digit of the number. Repeat steps 2 to 5 until the number becomes zero. UniqueNumberExample1.java import java.util.Scanner; public class UniqueNumberExample1 { public static void main(String args[]) { int r1, r2, number, num1, num2, count = 0; Scanner sc = new Scanner(System.in); System.out.print("Enter the number you want to check: "); //reading a number from the user number = sc.nextInt(); //num1 and num2 are temporary variable num1 = number; num2 = number; //iterate over all digits of the number while (num1 > 0) { //detrmins the last digit of the number r1 = num1 % 10; while (num2 > 0) { //finds the last digit r2 = num2 % 10; //comparing the last digit if (r1 == r2) { //increments the count variable by 1 count++; } //removes the last digit from the number num2 = num2 / 10; } //removes the last digit from the number num1 = num1 / 10; } if (count == 1) { System.out.println("The number is unique."); } else { System.out.println("The number is not unique."); } } } Output 1: Enter the number you want to check: 13895 The number is unique. Output 2: Enter the number you want to check: 11100 The number is not unique. Output 3: Enter the number you want to check: 10000 The number is not unique. Using String Using String, we can also check the number is unique or not. We use the charAt() method of the String to compare each digit of the string. UniqueNumberExample2.java import java.util.*; public class UniqueNumberExample2 { public static void main(String args[] ) { Scanner sc=new Scanner(System.in); System.out.print("Enter the number you want to check:"); //reading an integer from the user int number=sc.nextInt(); //converts integer data type into string String str= Integer.toString(number); //determines the length of the string int length=str.length(); int flag=0, i, j; //loop checks the digits are repeated or not for(i=0;i Output 1: Enter the number you want to check: 9876 The number is unique. Output 2: Enter the number you want to check: 1010 The number is not unique. Output 3: Enter the number you want to check: 200 The number is not unique. In the above program first, we convert the number variable into String by using the toString() method. After that, we determine the length of the string using the length() method. We have used two for loop (inner and outer) that iterate over the number. Inside the if statement, for each iteration, we have compared the digits by using the charAt() method. If both digits are the same, the break statement breaks the execution of the program and prints the number is not unique, else prints the number is unique. Using Array We can also use an array to check the number is unique or not. In this method, we find all the digits of the number and store it into an array. After that, compare the values of all the indexes with each other. If the values are the same, the number is not unique. Remember that before comparing all the indexes we required to declare the size of the array (number of digits). UniqueNumberExample3.java import java.util.Scanner; public class UniqueNumberExample3 { //static method that checks the number is unique or not public static boolean isUniqueNumber(int number) { //count the number of digits in a number int digits = countDigits(number); //declaring and creating an array of digits int[] arr = new int[digits]; for(int i=0; i← prev next →

Do birth stones work?
Do birth stones work?

Birthstones are more than just gems that align with each month. Each of them has a healing property that connects with the signs of the zodiac....

Read More »
How do you tell if God is helping you?
How do you tell if God is helping you?

It's been posited that God speaks to us through circumstances: blocked pathways, dreams, feelings, inspirations, music, nature, symbols, tender...

Read More »

Can someone increase their luck?
Can someone increase their luck?

The truth is you can increase your luck by learning the habits of successful people. You can improve your “luck score” by following the steps that...

Read More »
Which fruit is best for liver?
Which fruit is best for liver?

Fill your fruit basket with apples, grapes and citrus fruits like oranges and lemons, which are proven to be liver-friendly fruits. Consume grapes...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What do rich people regret?
What do rich people regret?

Even with much improved financial circumstances, it can take years to fully pay off the debts racked up from chemotherapy or major surgery. And...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What mineral attracts money?
What mineral attracts money?

Crystals for Prosperity FAQ The best crystals for money are gems that invite abundance. Citrine is known as the merchant's stone, Pyrite is called...

Read More »