Trending December 2023 # How To Check Whether A Number Is A Narcissistic Number Or Not In Java? # Suggested January 2024 # Top 21 Popular

You are reading the article How To Check Whether A Number Is A Narcissistic Number Or Not In Java? updated in December 2023 on the website Daihoichemgio.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 How To Check Whether A Number Is A Narcissistic Number Or Not In Java?

A number is said to be a narcissistic number, if the addition value of each digit raised to the power of numbers of digits available in the original number is equal to the original number.

For more clarification, if the original number has ‘n’ number of digits, first we have to calculate the nth power of each digit. Then add those value and check if that calculated value and original number both are same then the original number is called as narcissistic number.

Some examples of narcissistic numbers are: 153, 8208, 4210818, … etc.

In this article, we will see how to check if a number is a narcissistic number by using Java programming language.

To show you some instances

Instance-1

Input number is 153.

Let’s check it by using the logic of Narcissistic number.

Number of digits available in 153 is 3.

Calculate the power values and add those = (1^3) + (5^3) + (3^3) = 1 + 125 + 27 = 153

As we notice here both the calculated number and original number are same.

Hence, 153 is a narcissistic number.

Instance-2

Input number is 8208.

Let’s check it by using the logic of Narcissistic number.

Number of digits available in 8208 is 4.

Calculate the power values and add those = (8^4) + (2^4) + (0^4) + (8^4) = 4096 + 16 + 0 + 4096 = 8208

As we notice here both the calculated number and original number are same.

Hence, 8208 is a narcissistic number.

Instance-3

Input number is 250.

Let’s check it by using the logic of Narcissistic number.

Number of digits available in 250 is 3.

Calculate the power values and add those = (2^3) + (5^3) + (0^3) = 8 + 125 + 0 = 133.

As we notice here both the calculated number and original number are not same.

Hence, 250 is not a narcissistic number.

Algorithm

Step-1 – Get the input number by static input method.

Step-2 – Calculate the number of digits of the original number.

Step-3 – Initiate a loop to extract the digits and calculate the power value of it. Inside that loop add those calculated power values and store it into a variable.

Step-4 – Compare both the calculated value with the original number.

Step-5 – If the both are same, then the input number is called a narcissistic number else not.

Syntax

To get the power of any number raised to the power of another number in Java we have inbuilt java.lang.Math.pow() method.

Following is the syntax to get power of 2 by using the method –

double power = chúng tôi (inputValue,2) Multiple Approaches

We have provided the solution in different approaches.

By Using Static Input Value with User Defined Method

By Using User Defined Method with User Defined Method

Let’s see the program along with its output one by one.

Approach-1: By Using Static Input Value

In this approach, we declare a variable and initialize it with a number. Call a user defined method by passing this number as a parameter. Then inside the method by using the algorithm we can check whether the number is a narcissistic number or not.

Example import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String args[]) { int inputNumber = 8208; if (checkNarcissistic(inputNumber)) System.out.println(inputNumber + " is a narcissistic number."); else System.out.println(inputNumber + " is not a narcissistic number."); } static int countDig(int num) { if (num == 0) return 0; return 1 + countDig(num / 10); } static boolean checkNarcissistic(int num) { int p = countDig(num); int temp = num; int sum = 0; sum+= pow(temp % 10, p); temp = temp / 10; } return (num == sum); } } Output 8208 is a narcissistic number. Approach-2: By Using Static Input Value

In this approach, we declare a variable and assign a value to it by user input. Call a user defined method by passing this number as a parameter. Then inside the method by using the algorithm we can check whether the number is a narcissistic number or not.

Example import java.util.*; import static java.lang.Math.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number: "); int inputNumber = sc.nextInt(); if (checkNarcissistic(inputNumber)) System.out.println(inputNumber + " is a narcissistic number."); else System.out.println(inputNumber + " is not a narcissistic number."); } static int countDig(int num) { if (num == 0) return 0; return 1 + countDig(num / 10); } static boolean checkNarcissistic(int num) { int p = countDig(num); int temp = num; int sum = 0; sum+= pow(temp % 10, p); temp = temp / 10; } return (num == sum); } } Output Enter the number: 8208 8208 is a narcissistic number.

In this article, we explored how to check a number whether it is a narcissistic number or not in Java by using different approaches.

You're reading How To Check Whether A Number Is A Narcissistic Number Or Not In Java?

How To Check Whether A Number Is A Niven Number Or Not In Java?

Niven number can be defined as a number which is divisible by the sum of its digits. It is also called as Harshad number.

In this article we will see how to check Niven numbers by using the Java programming language.

To show you some instances Instance-1

Input number is 3

Let’s check it by using the logic of Niven number −

Sum of the digits of the number = 3.

So, 3 is divisible by 3.

Hence, 3 is a Niven number.

Instance-2

Input number is 18

Let’s check it by using the logic of Niven number −

Sum of the digits of the number = 1 + 8 = 9.

So, 18 is divisible by 9.

Hence, 18 is a Niven number.

Instance-3

Input number is 14

Let’s check it by using the logic of Niven number −

Sum of the digits of the number = 1 + 4 = 5.

So, 14 is not divisible by 5.

Hence, 14 is not a Niven number.

Some other examples of Niven numbers include 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20 etc.

Syntax

To convert integer value to String value by using inbuilt toString() method.

Following is the Syntax to get total number of digits in a number by converting the integer value to String value and then finding its length and assigning the length to an integer variable −

String str = Integer.toString(input_number);

To get the length of the Integer, we will use the Java String class inbuilt length() method which returns the length of the String object.

int length = st.length();

To get the character at a specific position/index in a string we use the charAt() method. Where charAt(i)-‘0’ returns the actual integer value.

int num = st.charAt(i)-‘0’;

Where ‘st’ refers to the string ‘i’ is the iterator variable to iterate the string.

Algorithm Algorithm 1

Step 1 − Get an integer number either by initialization or by user input.

Step 2 − By iterating each digit of the number, find the sum of each digit of the number.

Step 3 − Then check if the original number is divisible by the sum of all digits of the number. If divisible then the given number is a Niven number else it is not a niven number.

Algorithm 2

Step 1 − Get an integer number either by initialization or by user input.

Step 2 − Convert that integer to String by using inbuilt toString() method.

Step 3 − Find the length of the String by using the inbuilt length() method.

Step 4 − Then by using a for loop, iterate till the length of the String and get one by one integer value from String by using charAt(i)-‘0’ and keep a track on the sum of all digits.

Step 5 − Then check if the original number is divisible by the sum of all digits of the number. If divisible then the given number is a Niven number else it is not a niven number.

Multiple Approaches

We have provided the solution in different approaches.

Without Using String

By Using String

Let’s see the program along with its output one by one.

Approach-1: Without Using String

In this approach an integer value will be initialized in the program and then by using the Algorithm-1 we can check whether a number is a Niven number or not.

Example

public

class

Main

{

public

static

void

main

(

String

args

[

]

)

{

int

originalNumber

=

21

;

System

.

out

.

println

(

“Given number:”

+

originalNumber

)

;

int

copyOfOriginalNumber

=

originalNumber

;

int

sum

=

0

;

int

rem

=

originalNumber

%

10

;

sum

=

sum

+

rem

;

originalNumber

=

originalNumber

/

10

;

}

if

(

copyOfOriginalNumber

%

sum

==

0

)

System

.

out

.

println

(

copyOfOriginalNumber

+

” is a niven number”

)

;

else

System

.

out

.

println

(

copyOfOriginalNumber

+

” is not a niven number”

)

;

}

}

Output Given number:21 21 is a niven number Approach-2: By Using User Defined

In this approach an integer value will be initialized in the program then by using the Algorithm-2 we will check if the number is a niven number or not.

Example

public

class

Main

{

public

static

void

main

(

String

args

[

]

)

{

int

originalNumber

=

40

;

System

.

out

.

println

(

“Given number:”

+

originalNumber

)

;

int

copyOfOriginalNumber

=

originalNumber

;

int

sum

=

0

;

String

str

=

Integer

.

toString

(

originalNumber

)

;

int

length

=

str

.

length

(

)

;

for

(

int

i

=

0

;

i

<

length

;

i

++

)

{

sum

+=

str

.

charAt

(

i

)

‘0’

;

}

if

(

copyOfOriginalNumber

%

sum

==

0

)

System

.

out

.

println

(

copyOfOriginalNumber

+

” is a niven number”

)

;

else

System

.

out

.

println

(

copyOfOriginalNumber

+

” is not a niven number”

)

;

}

}

Output Given number:40 40 is a niven number

In this article, we explored how to check a number whether it is a niven number or not in Java by using different approaches.

Swift Program To Find The Given Number Is Strong Or Not

A strong number is a special number in which the sum of the factorial of its digit is equal to the number itself. For example −

Number = 345

345! = 3! + 4! + 5! = 6 + 24 + 120 = 150

Here 345 is not a strong number because the sum of the factorial of its digit is not equal to the number itself.

Number = 145

145! = 1! + 4! + 5! = 1 + 24 + 120 = 145

Here 145 is a strong number because the sum of the factorial of its digit is equal to the number itself.

In this article, we will learn how to write a swift program to find the given number is strong or not.

Algorithm

Step 1 − Create a function.

Step 2 − Create a copy of the original number and initialize sum = 0.

Step 3 − Run while to find the last digit of the given number.

Step 4 − Now find the factorial of all the individual digits of the given number.

Step 5 − Add the factorial of the digits and store the result in the sum variable.

Step 6 − Compare the sum and the original number. Return true if the sum and original number are equal. Otherwise, return false.

Step 7 − Create a test variable to store the number and pass it to the function.

Step 8 − Print the output.

Example

Following the Swift program to find whether the given number is strong or not.

import Foundation import Glibc var originalNum = num var sum = 0 let lDigit = originalNum % 10 var factorial = 1 for x in 1...lDigit { factorial *= x } sum += factorial originalNum /= 10 } return sum == num } let myInput = 345 if CheckStrongNumber(num: myInput) { print("YES! (myInput) is a strong number.") } else { print("NO! (myInput) is not a strong number.") } let myInput2 = 145 if CheckStrongNumber(num: myInput2) { print("YES! (myInput2) is a strong number.") } else { print("NO! (myInput2) is not a strong number.") } Output NO! 345 is not a strong number. YES! 145 is a strong number. Conclusion

Here in the above code, we have two numbers that are 345 and 145. Now we create a function to check if the given numbers are strong numbers or not. In this function, first, we first make a copy of the original number and initialize the sum to 0. Now we run a while loop to repeatedly extract the last of the number and then perform the factorial of that digit and add the factorial result to the sum. Then the function checks if the given number is equal to the sum of the factorial of the digits. If yes then the function returns true. Otherwise, return false.

So this is how we can check if the given number is a strong number or not.

How To Track A Phone Number With Ease

Whether your kid, who’s alone at home or your partner, who often returns late, keeping an eye out for their whereabouts is essential for their safety. However, you can’t track someone’s phone number whenever you wish to, just like that. Actually, you can! Thanks to Spyic and its neat call tracking feature. We have thoroughly tested the feature, and here’s what we feel about it.

Spyic: The Easiest Way to Track Someone’s Phone Number

While most phones come with an SOS Emergency feature, they are only useful in extreme circumstances. Similarly, with location sharing feature on Apple Maps, Google Maps, etc., the user has to manually activate the setting and then only see or track their location.

But what if you want to track a phone without such restrictions, anytime and from anywhere? Spyic could be the thing you need.

Spyic is a top-rated and effective spy app for iOS and Android devices. Packed with intensive features, it aids you in monitoring your children or partner’s devices remotely. It gives you access to;

Log calls

SMS & iMessage

Location & Geo-Fencing

Browser History

Contacts

Photos & Videos

Applications

Social Media notifications

Keylogger (only for Android)

A part of Spyic feature-packed service is its ability to track any device remotely. Wherein, you can check out GPS-and-Wi-Fi-based locations of the device and its SIM card along with Timestamps.

So, you can literally track the device’s moments throughout the day, week, or more.

Why Should You Use Spyic Phone Tracking Apps?

While the features, as mentioned earlier, are enough to sell the app, there are few more perks that you avail when you opt Spyic.

1. No Jailbreak or Root: That’s right Spyic smartly integrates with your device’s operating system without the necessity of root or jailbreaking the target phone.

2. Unique Design: Spyic is a master of disguise. Firstly, it sneakily hides in the device. It does not show up in the app library and wouldn’t notify the target user that they are being tracked in any way unless you tell them.

Notably, even the malicious person who may try to steal the device or harm your loved ones know about, wouldn’t know that Spyic is operating in stealth mode.

3. Web-based Interface: Don’t have ample technical knowledge? Don’t worry, Spyic is super-duper easy to use, thanks to a web dashboard.

All you have to do is log in and check the details you want to in just some taps.

4. Cheap Pricing Model: You might expect software with so many features to charge a bomb. But Spyic is reasonably priced, whether you are looking to monitor an individual device or the whole enterprise.

Tip: Opt for a yearly subscription, as that would come at a much-budgeted price.

Use Spyic to Track Phone Number’s Location Online

As mentioned earlier, Spyic is pretty easy to use. Start by signing up on Spyic’s website and make payments according to the package selected. Then log in to your account and follow the onscreen instruction to add the target device.

Once all the data is synced, it may take a few minutes, you can start monitoring.

Also, Spyic lets you create Geo-Fence. The feature forms a digital location boundary for the target user. And, in case the device crosses this boundary, you’ll be sent an alert instantly.

Our Verdict

Spyic is a wholesome app to monitor or track a device, even without the target user knowledge. Though with all those features, you might find it a bit more intrusive. Thankfully you can decide what or what not to monitor and accordingly set the permissions.

However, you will have to pay for the full package. It would have been great if the software offered both segregated services and a subscription bundle. Hopefully, that could be a part of future updates.

Another issue, the app doesn’t sync if the device is switched off and would not track location. Though it will show you the last site with a proper timestamp. Apart from that, we loved the overall usage and use-case of Spyic.

It should also be noted that Spyic is intended for legal use only, and “the law generally requires you to notify users/ owners of the device that it is being monitored. The violation of this requirement could result in severe monetary and criminal penalties imposed on the violator,” as stated in a developer’s disclaimer.

Price: The basic plan for

Android devices start from $39.99/month

iOS devices start from 99.99/month

Author Profile

Arshmeet

A self-professed Geek who loves to explore all things Apple. I thoroughly enjoy discovering new hacks, troubleshooting issues, and finding and reviewing the best products and apps currently available. My expertise also includes curating opinionated and honest editorials. If not this, you might find me surfing the web or listening to audiobooks.

How To Check Imei Number Of Iphone And Android

How To Check IMEI Number of iPhone and Android What is IMEI?

IMEI (International Station Equipment Identity) is a unique 15 or 16 string assigned to each mobile device. It is linked with a SIM slot and each phone from a basic to high-end every phone has its own IMEI.

This number is used to identify the device.

Now, let’s look at how to check the IMEI number.

Before we being a word of caution never share your IMEI number publicly as IMEI based scams are on the rise.

How to Check Phone’s IMEI Number Using USSD code

This one is the easiest and quickest method to check IMEI number. The best part about this technique is it is universal. This means it will work on all devices with cellular connectivity be it Android, iPhone, tablet or any other.

1. Dial *#06# on your phone.

2. This will display the IMEI number on your screen. You can take a screenshot of it or can not it down. Remember if you are using a dual SIM phone you’ll see two IMEI numbers.

Using these simple steps you can check IMEI of Apple and Android devices.

How to Check iPhone IMEI Number?

If you are using iPhone 5 or higher version, you can use the above method or can flip the phone as IMEI is engraved on the back panel. However, if you are using iPhone 4s or older iPhones, you’ll need to check the SIM tray for the IMEI number.

How to Check Phone’s IMEI Number on iPhone and Android Devices.

To check iPhone’s IMEI follow the steps below:

2. Here you will be able to check the iPhone IMEI number.

4. In addition to this, if you are using a phone with a removable battery you can remove it to check the IMEI number of the phone.

However, if you don’t have the device then you can follow the method explained below to check the IMEI number.

How to check IMEI when you don’t have a mobile phone?

If you don’t have the device, you can look for the IMEI number on the retail box or bill. On the side of the box, you will see a sticker with the IMEI  number of the device. This is why keeping a bill and phone box is recommended.

Can I check the IMEI number of my lost Android device?

Yes, Android users can check their device’s IMEI number even when they’ve lost the phone. To do so, follow the steps below:

2. Now login to the Google account linked with the lost Android phone.

4. You will now see a list of devices registered with the account along with their IMEI numbers.

Must Read: Can Your Phone Be Hacked By Your IMEI Number?

How to find serial number of Apple devices?

To find the serial number of Apple devices follow the steps below:

1. Connect your Apple device with the PC.

2. Open Finder on Mac running macOS 10.15 Catalina and later. However, if you are running Mojave 10.14 open iTunes.

Moreover, if you don’t have the Apple device then also you can check iPhone IMEI. To do so follow the steps below.

Steps to check IMEI number when you don’t have Apple devices

2. Log in to your account using the same Apple ID you are signed into with on the lost device.

3. Scroll down to the Devices section. Here you will be able to check the IMEI number of Apple devices.

That’s it using these simple steps you can check the IMEI number on Android, iPhone and other devices with cellular connectivity. A word of caution, do not share your IMEI number with anyone. We hope you find these steps useful. If you have lost your device or don’t have the bill still you can check IMEI by heading to Google Dashboard (Android users) and chúng tôi (iPhone users).

Do let us know what you think about this article and did you find it helpful.

Quick Reaction:

About the author

Preeti Seth

How To Fix Number Keypad Not Working In Windows 10?

How to Fix Number Keypad Not Working in Windows 10? How to Fix Number Pad Not Working in Windows 10?

There are multiple solutions to fix number keypad not working. It includes fixing hardware issues, updating software, tweaking system settings, and more. Let’s discuss how to do it?

Solution 1: Restart your PC Solution 2: Check for hardware issues

Next step is to look for hardware (keyboard) issues. Here, make sure everything is fine with the keyboard physically. You should check for broken parts and other issues that could affect the functioning of your keyboard. You can try to connect it to another PC to check if the problem is with your keyboard or the system itself. You can also try a virtual keyboard or try an external keyboard on your PC to ascertain this.

Solution 3: Enable the Num Lock key

This is no brainer if you are using a number keypad, you should enable Num Lock key first. Or at least check it is enabled. If it is disabled, then enable it and try using your number keypad in Windows 10.

Solution 4: Turn off mouse keys

Press Win + R keys to open Run

Here, input Control Panel and press Enter.

Now on the Control Panel window, select Ease of Access Center from left pane.

On the next window make sure Turn on Mouse Keys under Control the mouse with the keyboard is unchecked.

You’re done. Check if number keys are working now.

Solution 5: Update keyboard drivers

Updating keyboard drivers is the next best solution you can follow to fix the number pad not working on Windows 10. As outdated drivers could cause a lot of issues with hardware devices and affects overall system performance, it is suggested to keep drivers up to date to avoid performance issues. Here, you need to update keyboard drivers to fix the issue with the number keypad. To do this, follow these steps:

Press Win + X keys and select Device Manager.

Once you are on Device Manager window, find and expand Keyboards

Use Best Driver Updater Software

If you find the manual process too complicated to update drivers, then we suggest you should use the best driver updater software. One such tool is Smart Driver Care that helps you update all your outdated, missing, incompatible, and corrupt drivers automatically. It helps you take backup of existing drivers before making any changes. It is useful to undo action if something goes wrong with the update.

Conclusion

Next Read: 

Best Keyboard Apps for Android & iOS

All About Windows 10 Keyboard Shortcuts

Quick Reaction:

About the author

Dinesh Lakhwani

Update the detailed information about How To Check Whether A Number Is A Narcissistic Number Or Not In Java? on the Daihoichemgio.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!