Infosys Java8 Coding Interview Question Answers

Infosys Java8 Coding Interview Question Answers

CloudTech

1 год назад

7,636 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Muhil kannan
Muhil kannan - 08.06.2023 09:28

Like these questions are asking for interview of java developer with 2years experience sir? Is it for Sure sir?? Im preparing now thats why asked !

Ответить
Akshay Tejale
Akshay Tejale - 19.04.2023 18:31

Thanks a lot

Ответить
vijay kumar
vijay kumar - 24.01.2023 08:15

thank u so much brother

Ответить
Jeck Razi
Jeck Razi - 20.01.2023 09:51

Hi @CloudTech

One more way


import java.util.*;
import java.util.stream.*;

public class MyClass {
public static void main(String args[]) {
List<Integer> intList = Arrays.asList(10,6,2,6,4,8);
int totalSum = intList.stream().mapToInt(Integer::intValue).sum();
int towDivisibleSum = intList.stream().filter(p -> p % 2 == 0).reduce(Integer::sum).orElse(0);

if(totalSum == towDivisibleSum)
System.out.println("All the numbers are divisible by 2");
else
System.out.println("All the numbers are NOT divisible by 2");

}
}

Ответить
Jeck Razi
Jeck Razi - 19.01.2023 21:12

Hi @CloudTech,
The other way is given below


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class MyClass {
public static void main(String args[]) {
List<Integer> intList = Arrays.asList(2,2,8,6,4,10,890,90004,890000063);
long divTwoList = intList.stream().filter(p-> p % 2 == 0).count();
if(divTwoList == intList.size())
System.out.println("All numbers in the given list are divisible by 2");
else
System.out.println("All numbers in the given list are NOT divisible by 2");
}
}

Ответить
Panneer Selvam
Panneer Selvam - 19.01.2023 19:24

without using streams how to do?

Ответить
saurabh firke
saurabh firke - 19.01.2023 13:45

can u please also provide interview questions?

Ответить
saurabh firke
saurabh firke - 19.01.2023 13:40

are these recent interviews?

Ответить
Gow Tham
Gow Tham - 19.01.2023 09:27

Great Thanks.

Ответить
Jeck Razi
Jeck Razi - 19.01.2023 08:51

That helps a lot.
Thanks a zillion.
The other way to get the desired output is

import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class MyClass {
public static void main(String args[]) {
List<Integer> intList = Arrays.asList(2,4,6,8);
Long totalNum = intList.stream().collect(
Collectors.filtering(x-> x % 2 == 0,
Collectors.counting()
)
);

if(totalNum == intList.size())
System.out.println("All the numbers are divisible by 2");
else
System.out.println("All the numbers are not divisible by 2");

}
}

Ответить