Hello, folks today I bring to you another important programming interview questions for you.
The questions now showing are already asked in a company interview process so look at those questions and answers I have given below.
If you want to see the previous posts I have given the links below click on them and see them.
Also, Read
I'll give you some important Java Generics and Collections articles links below take a look once.
Study the Following Articles:
Java Generics and Collections:
- https://www.codejava.net/java-core/collections/what-is-java-collections-framework
- https://www.codejava.net/java-core/collections/what-are-generics-in-java
- https://www.codejava.net/java-core/collections/how-to-write-generic-classes-and-methods-in-java
- https://www.codejava.net/java-core/collections/java-list-collection-tutorial-and-examples
- https://www.codejava.net/java-core/collections/java-set-collection-tutorial-and-examples
- https://www.codejava.net/java-core/collections/java-map-collection-tutorial-and-examples
Java NIO:
Reading Java NIO Concepts will give you a complete understanding of them.
Simple interview questions on Java NIO Generics and Collections:
1. Did you know Java NIO and Java Generics and Collections already?
2. How long did you spend reading Java articles, including additional articles and books?
3. Rate yourself in between 1 to 10 on Java NIO and Generics, Collections proficiency?
4. Did you study additional articles or any books to understand the concept further?, If Yes provide the article links and book details.
Questions:
1. Write a function or a method to find out the second largest number given a set of natural numbers in the form of an Array. You are not supposed to use Sort. Also indicate the complexity of the algorithm.
Ex: Input : [4, 10, 2, 6, 10, 7] Output : 7
2. Write a program to print numbers in the following fashion.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 6 7 8 9 10
1 2 3 4
1 2 3
1 2
1
3. Write a function or a method that returns 0 given 1 and 1 given 0 without using an if the condition or a colon operation. You are supposed to use only the following operators ( +, - , x , / , % ).
Check the below code:
File Name: SecondLargest.java
package chaitu.info.blogs;
import java.util.HashSet;
import java.util.Scanner;
public class SecondLargest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter the array size");
int size = scanner.nextInt();
int[] input = new int[size];
int count = 0;
System.out.println("enter the array elements");
for(int i=0;i<size;i++) {
int temp = scanner.nextInt();
int duplicate = 0;
for(int j=i-1;j>=0;j--) {
if(input[j]==temp) {
duplicate++;
}
}
if(duplicate==0) {
count++;
input[i] = temp;
}
}
for(int i=0;i<size;i++) {
int big = 0;
for(int j=0;j<size;j++) {
if(input[j]>input[i]) {
big++;
}
}
if(big==1) {
System.out.println(input[i]);
break;
}
}
}
}
Result:
File Name: Pattern.java
package chaitu.info.blogs;
public class Pattern {
public static void main(String[] args) {
for(int i=1;i<=9;i++) {
if(i<=5) {
for(int j=1;j<=i;j++) {
System.out.print(j+" ");
}
}
if(i>5) {
for(int k=1;k<=10-i;k++) {
System.out.print(k+" ");
if(i==8) {
int temp = k+1;
System.out.print(" "+temp);
break;
}
}
}
System.out.println();
}
}
}
Result:
File Name: ConditionMethod.java
package chaitu.info.blogs;
import java.util.Scanner;
public class ConditionMethod {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enyter single digit 0 or 1");
int input = scanner.nextInt();
System.out.println((input+1)%2);
}
}
Result:
If you like this article please share it with your friends who are preparing for interviews and also follow my blog for more interesting updates.
1 Comments
Your asome bro..👌
ReplyDelete