Java Hyd Team
746 subscribers
986 photos
39 videos
670 files
690 links
https://teamhydteam.my.canva.site/

Can visit us on our website ๐Ÿ˜Š
Still working on it ๐Ÿ˜Š
Download Telegram
Java Hyd Team
Photo
Best shot of the day ๐Ÿ‘ป
Java Hyd Team pinned ยซOne question for you all where is main method in these codes ?? And if not why notยป
One message for you all you will never see these codes with main method without main method you can't excute codes in normal IDE so these codes will only work on competitive coding platforms for normal IDE you can just copy logic n use methods n constructors
Java Hyd Team pinned ยซOne message for you all you will never see these codes with main method without main method you can't excute codes in normal IDE so these codes will only work on competitive coding platforms for normal IDE you can just copy logic n use methods n constructorsยป
// Thread synchronization


import java.util.*;
import java.lang.*;

public class Number{

static int x;
synchronized static void increment(){
x++;
}
}
class First extends Thread {
public void run(){
for(int i= 1 ; i<= 100000 ; i++){
Number.increment();
}
}
}
class Second extends Thread{
public void run(){
for(int i= 1 ; i<= 100000 ; i++){
Number.increment();
}
}
}
class Synchronization{
public static void main(String[] args) {
First f = new First();
Second s = new Second();
f.start ();
s.start();
try{
f.join();
s.join();
} catch (Exception e ){
}
System.out.println("Final x value " + Number.x);
}
// creating threads using runnable interface

//runnable interface has only one specification called run()
// we can't start runnable object directly
// we can create the thread object by passing runnable object as parameter
// we can execute the thread logic by starting thread '

public class Main {
public static void main(String[] args) {
First f = new First ();
// f.start (); error
Thread t = new Thread (f);
t.start();
}
}
class First implements Runnable {
public void run(){
System.out.print("thread logic ");
}
}
๐Ÿ‘1
//Find sum of n numbers through threading ...


import java.util.*;
public class Defaults {
static int n ;
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.print("Sum of N numbers ");
System.out.print("Enter N number ");
n = x.nextInt();
Calculation Thread = new Calculation();
Thread.start();
try{
Thread.join();}
catch(Exception e ){}
System.out.print("Sum "+Calculation.sum);
}
}
class Calculation extends Thread{
static int sum =0;
public void run(){
System.out.print("Calc Started ");
for(int i = 1 ; i<= Defaults.n ; i++){
Calculation.sum= Calculation.sum+i;
}
System.out.print("Calc ends ");
}
}
import java.util.*;

class Employee{
int id ;
double Salary;
String name;
Employee (int id , String name , double Salary){
this .id = id;
this.name= name;
this.Salary= Salary;
}}
public class Main{
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
List<Employee> list = new Arraylist<Employee> ();
while (true){
System.out.print("1. Append \n 2. Display Record \n 3. Display All Record \n 4. Update \n 5. Delete \n 6. Exit");
if (ch == 1){
System.out.print(" Enter details");
int id = x.nextInt();
String name = x.next();
double Salary = x.nextDouble();
Employee e = new Employee (id, name, Salary);
list.add(e);
System.out.print("Record added");
}
else if (ch== 2){
if(list.isEmpty()){
System.out.print("Empty list ");
}
else
{
System.out.print("Details");
for(Employee e : list){
System.out.print(e.id + e.name + e.Salary);
}
}
System.out.print("Enter id");
int id = x.nextInt();
boolean found = false ;
for (Enployee e : list){
if ( e.id == id ){
System.out.print(e.name + e.Salary);
found = true ;
break ;
}
}if ( ! found )
System.out.print("invalid Id");
}

else if (ch== 3){
if ( list.isEmpty()){
System.out.print("Empty list");
}else{
System.out.print("Details");
for(employee e : list)
System.out.print(e.id+ e.name + e.Salary );
}
} else if (ch== 4){
if ( list.isEmpty()){
System.out.print("Empty list");
}else{
System.out.print("Enter Id");
int id = x.nextInt();
boolean found = false;
for(employee e : list)
{
if (e.id == id)
System.out.print("Enter salary to update ");
double Salary = x.nextDouble();
e.Salary = Salary;
System.out.print("Updated");
found = true ;
}
}
Q1
Solve the errors
/**
* Returns a string representation of the object.
* @apiNote
* In general, the
* {@code toString} method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read.
* It is recommended that all subclasses override this method.
* The string output is not necessarily stable over time or across
* JVM invocations.
* @implSpec
* The {@code toString} method for class {@code Object}
* returns a string consisting of the name of the class of which the
* object is an instance, the at-sign character `{@code @}', and
* the unsigned hexadecimal representation of the hash code of the
* object. In other words, this method returns a string equal to the
* value of:
* <blockquote>
* <pre>
* getClass().getName() + '@' + Integer.toHexString(hashCode())
* </pre></blockquote>
*
* @return a string representation of the object.
*/
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.



Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.
Example 2:

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:

Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.


Constraints:

3 <= nums.length <= 3000
-105 <= nums[i] <= 105
Sorted the array to be able to use binary search O((N * log(N)). Picking two numbers O(N * N) and finding the third one by binary searching O(log(N)). Adding the sorted result to the set to make sure that the combination of 3 numbers is unique. Then returning the result.
Binary search compares the target value to the middle element of the array. It works only on a sorted set of elements.
When the binary search is used to perform operations on a sorted set, the number of iterations can always be reduced on the basis of the value that is being searched. You can see in the above snapshot of finding the mid element. The analogy of binary search is to use the information that the array is sorted and reduce the time complexity to O(log n).
๐Ÿ˜’๐Ÿ˜’ it took 1755 milliseconds to execute
This media is not supported in your browser
VIEW IN TELEGRAM
When you are out of social life for more than a year
Focus on medium level questions for maang companies