Java
Peterson Number Java Program In the following program, we have taken an array of factorial to quickly find the factorial. You can use the logic also. #Source_code #71
Steps to Find Peterson Number
* Read or initialize a number (n).
* Find the last digit (d) of the given number.
* Find the factorial (fact) of the digit.
* Add the factorial (fact) to a variable
* Repeat steps 2 to 4 until the given number becomes 0.
* Compare the sum with n. If both are equal, the given number is Peterson, else not.
#Output
#71
* Read or initialize a number (n).
* Find the last digit (d) of the given number.
* Find the factorial (fact) of the digit.
* Add the factorial (fact) to a variable
* Repeat steps 2 to 4 until the given number becomes 0.
* Compare the sum with n. If both are equal, the given number is Peterson, else not.
#Output
#71
Sunny Number
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. Let's understand it through an example. #Source_code #72
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
Sunny Number
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
#Source_code
#73
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
#Source_code
#73
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. #Source_code #73
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
#Output
#73
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
#Output
#73
Find the Duplicate element in a limited range array
Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space.
#Data_structure
Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space.
#Data_structure
Fascinating Number Java Program
The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits.
#Source_code
#75
The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits.
#Source_code
#75
Java
Fascinating Number Java Program The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits. #Source_code #75
Steps to Find Fascinating Numbers
First, check the given number consist of three digits or not. If no, print cannot be a fascinating number.
Else, multiply the given number by 2 and 3, separately.
Convert the results (from step 2) into a string.
Concatenate the strings (from step 3) with the given number (n).
Iterate over the string that we get after concatenation and count the frequency of each digit.
Print "not a fascinating number" if any digit is missing or appeared multiple times. Else, print "fascinating number".
Let's implement the above steps in a Java program
#Output
#75
First, check the given number consist of three digits or not. If no, print cannot be a fascinating number.
Else, multiply the given number by 2 and 3, separately.
Convert the results (from step 2) into a string.
Concatenate the strings (from step 3) with the given number (n).
Iterate over the string that we get after concatenation and count the frequency of each digit.
Print "not a fascinating number" if any digit is missing or appeared multiple times. Else, print "fascinating number".
Let's implement the above steps in a Java program
#Output
#75
Using the Random Class
Another way to generate a random number is to use the Java Random class of the java.util package. It generates a stream of pseudorandom numbers. We can generate a random number of any data type, such as integer, float, double, Boolean, long. Of you are going to use this class to generate random numbers, follow the steps given below:
* First, import the class java.lang,Random
* Create an object of the Random class.
* Invoke any of the following method:
* nextInt(int bound)
* nextInt()
* nextFloat()
* nextDouble()
* nextLong()
* nextBoolean()
All the above methods return the next pseudorandom, homogeneously distribute value (corresponding method) from this random number generator's sequence. The nextDouble() and nextFloat() method generates random values between 0.0 and 1.0.
The nextInt(int bound) method accepts a parameter bound (upper) that must be positive. It generates a random number in the range 0 to bound-1.
#Source_code
#20
Another way to generate a random number is to use the Java Random class of the java.util package. It generates a stream of pseudorandom numbers. We can generate a random number of any data type, such as integer, float, double, Boolean, long. Of you are going to use this class to generate random numbers, follow the steps given below:
* First, import the class java.lang,Random
* Create an object of the Random class.
* Invoke any of the following method:
* nextInt(int bound)
* nextInt()
* nextFloat()
* nextDouble()
* nextLong()
* nextBoolean()
All the above methods return the next pseudorandom, homogeneously distribute value (corresponding method) from this random number generator's sequence. The nextDouble() and nextFloat() method generates random values between 0.0 and 1.0.
The nextInt(int bound) method accepts a parameter bound (upper) that must be positive. It generates a random number in the range 0 to bound-1.
#Source_code
#20
Media is too big
VIEW IN TELEGRAM
Java Virtual Threads
Concurrent applications, those serving multiple independent application actions simultaneously, are the bread and butter of Java serving-side programming. The thread has been Java's Primary unit of concurrency since its inception and is core to the entire Java platform. However, it can no longer efficiency represent a domain unit of concurrency. As a result, Java has seen a proliferation of libraries and frameworks that offer scalability while abandoning the thread as the unit of software concurrency - and, with it, the support of Java's observability tooling. In this session, learn how Project Loom aims to reinstate the thread as an efficient unit of concurrency by adding a lightweight implementation of threads of the Java platform.
Concurrent applications, those serving multiple independent application actions simultaneously, are the bread and butter of Java serving-side programming. The thread has been Java's Primary unit of concurrency since its inception and is core to the entire Java platform. However, it can no longer efficiency represent a domain unit of concurrency. As a result, Java has seen a proliferation of libraries and frameworks that offer scalability while abandoning the thread as the unit of software concurrency - and, with it, the support of Java's observability tooling. In this session, learn how Project Loom aims to reinstate the thread as an efficient unit of concurrency by adding a lightweight implementation of threads of the Java platform.
Java
#Source_code #76
Spy Number
A positive integer is called a spy number if the sum and product of its digits are equal. In other words, a number whose sum and product of all digits are equal is called a spy number.
#Output
#76
A positive integer is called a spy number if the sum and product of its digits are equal. In other words, a number whose sum and product of all digits are equal is called a spy number.
#Output
#76