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
public T newInstance(Objects...initargs)
public class Test {
public static void main(String[] args) {
String input = "sat23h6y7a8";
int sum = 0;
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (Character.isDigit(ch)) {
sum = sum + Integer.parseInt(String.valueOf(ch));
}
}
System.out.println(sum);
}
}
Difference between final finally and finalize

The main difference between final, finally, and finalize in Java is that final is a keyword, finally is a block, and finalize is a method.

A final variable can only be assigned once and it cannot be changed.
A finally block is used to execute important code such as closing a connection, stream, or file.
A finalize method is used to perform cleanup operations before an object is destroyed.
//Write a java program for Fibonacci Series from 1 to 100?

public class FibonacciExample1 {
public static void main(String[] args) {
int n1=0,n2=1,n3,i,count=100;
System.out.print(n1+" "+n2);//printing 0 and 1

for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}

}}
int nums []= x.nextInt();
int[] count = new int[101];
int[] res = new int[nums.length];

for (int i =0; i < nums.length; i++) {
count[nums[i]]++;
}

for (int i = 1 ; i <= 100; i++) {
count[i] += count[i-1];
}

for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0)
res[i] = 0;
else
res[i] = count[nums[i] - 1];
}

return res;
}
import java.io.*;
import java.util.Scanner;

public class NumerSmallerThanCurrentNumber {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Enter the size of array : ");
int n = scanner.nextInt();


//Declaring the array
int arr[] = new int[n];

System.out.println("Enter the array elements : ");

for(int i=0;i<n;i++) {
arr[i] = scanner.nextInt();
}

System.out.println("The Entered elements are : ");
for(int i=0;i<n;i++) {
System.out.print(arr[i] + " ");
}

int listOfElements[] = countSmallerNumber(arr);

System.out.println("\nThe list of numbers smaller than current number : ");

for(int i=0;i<listOfElements.length;i++) {

System.out.print(listOfElements[i]+" ");
}
}

//Function for count the smaller element than the current element
private static int[] countSmallerNumber(int[] arr) {

//Take a array for storing the the count of smaller element than the current element
int countNumber[] = new int[arr.length];

for(int i=0;i<arr.length;i++) {

int count=0;

for(int j=0;j<arr.length;j++) {

//Compare current elements with other elements
if((arr[i]>arr[j]) && (i!=j)) {

//Increase the count, if other element is smaller than the current element
count++;
}
}
countNumber[i]=count;
}

return countNumber;
}
}
Cadence is Hiring Software Engineer Intern
Role : SDE intern
Experience: Student
Batch - 2022 /2023 /2024
Qualification - pursuing or completed B.E/B.Tech/M.E/M.Tech
Location: Remote ( Work from home)
Salary: 40k - 45k per month
Duration: 11 month



Apply now: https://www.linkedin.com/jobs/view/3274286602
Java Hyd Team
import java.io.*; import java.util.Scanner; public class NumerSmallerThanCurrentNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the size of array : "); int n = scanner.nextInt();โ€ฆ
HashMap<Integer,Integer> m= new HashMap<>();
int[] nums1= nums.clone();
Arrays.sort(nums);
int[] result= new int[nums.length];
for(int i=0;i<nums.length;i++){
if(!m.containsKey(nums[i])){
m.put(nums[i],m.getOrDefault(nums[i],i));
}
}
for(int j=0;j<nums.length;j++){
result[j]=m.get(nums1[j]);
}

return result;
}
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
List<Integer> inp = Arrays.asList(8, 1, 2, 2, 3);
List<Integer> al = Arrays.asList(8, 1, 2, 2, 3);
Collections.sort(al);
Map<Integer, Integer> o = new HashMap<>();
List<Integer> res = new ArrayList<>();
for(int i = 0; i < al.size(); i++){
if (i != 0 && al.get(i) == al.get(i-1)) {
o.put(al.get(i), i-1);
} else {
o.put(al.get(i), i);
}
}
for(int i = 0; i < inp.size(); i++) {
res.add(o.get(inp.get(i)));
}

System.out.println(res.toString());
}
}
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
class HelloWorld {
public static void main(String[] args) {
//List<Integer> al = Arrays.asList(8, 1, 2, 2, 3);
int[] l = new int[5];
int[] o = new int[5];
l[0] = 8;
l[1] = 1;
l[2] = 2;
l[3] = 2;
l[4] = 3;

for(int i = 0;i<l.length;i++){
int count = 0;
for(int j = 0; j < l.length; j++){
if(l[i] > l[j]){
count++;
}
}
o[i] = count;
}
ArrayList<Integer> integerArray = (ArrayList<Integer>) Arrays.stream(o).boxed().collect(Collectors.toList());
System.out.println(integerArray.toString());
for(int i = 0;i<l.length;i++){
System.out.println(o[i]);
}
}
}
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
List<Integer> i1 = Arrays.asList(2, 4, 3);
List<Integer> i2 = Arrays.asList(5, 6, 4);
List<Integer> o = new ArrayList<>();
int d = 0;
for(int i = 0; i < i1.size(); i++){
int x = i1.get(i) + i2.get(i);
if (x > 9) {
d = x/10;
int r = x%10;
x = d>0 ? r : x;
} else {
x = d>0 ? (x + d) : x;
}

o.add(x);
}
System.out.println(o.toString());
}
}