163 subscribers
3.42K photos
24 videos
39 files
371 links
Link: @java_posts

Contact: java.response.email@gmail.com
Download Telegram
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
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
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
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
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.
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
code
342.3 KB
In-place merge two sorted arrays
The time complexity of the above solution is O(m.n), where m is the size of the first array and n is the size of the second array. The solution doesn’t require any extra space. The problem, in fact, can be solved in linear time and constant space.
#Data_structure
#Source_code
Java
code
Given two sorted arrays, X[] and Y[] of size m and n each, merge elements of X[] with elements of array Y[] by maintaining the sorted order, i.e., fill X[] with the first m smallest elements and fill Y[] with remaining elements.
#Data_structure
In this program, we need to copy all the elements of one array into another. This can be accomplished by looping through the first array and store the elements of the first array into the second array at the corresponding position.
#Source_code
#78
Using clone() Method
The clone() method is the method of Object class. It creates a copy of an object and returns the same copy. The JVM creates a new object when the clone() method is invoked. It copies all the content of the previously created object into new one object. Note that it does not call any constructor. We must implement the Cloneable interface while using the clone() method. The method throws CloneNotSupportedException exception if the object's class does not support the Cloneable interface. The subclasses that override the clone() method can throw an exception if an instance cannot be cloned
#Source_code
#57
Pattern 2
#Source_code
#38
The idea is to traverse both trees and compare values at their root node. If the value matches, recursively check if the first tree’s left subtree is identical to the left subtree of the second tree and the right subtree of the first tree is identical to the right subtree of the second tree. If the value at their root node differs, the trees violate data property. If at any point in the recursion, the first tree is empty and the second tree is non-empty, or the second tree is empty and the first tree is non-empty, the trees violate structural property, and they cannot be identical.
#Data_structure
#Source_code
code.png
511.2 KB
ATM program Java
In Java, we can create an ATM program for representing ATM transection. In the ATM program, the user has to select an option from the options displayed on the screen. The options are related to withdraw the money, deposit the money, check the balance, and exit.
#Source_code
#79