Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Rating | ||||
![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { for(int x=1;x<=5;x++){ for(int y=1;y<=x;y++){ System.out.print("*"); } System.out.print("_"); } for(int x=5;x>=1;x--){ for(int y=1;y<=x;y++){ System.out.print("*"); } System.out.print(""); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { for(int x=1;x<=5;x++){ for(int y=1;y<=x;y++){ System.out.print("*"); } System.out.println(""); } for(int x=5;x>=1;x--){ for(int y=1;y<=x;y++){ System.out.print("*"); } System.out.println(""); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { for(int x=1;x<=10;x++){ for(int y=1;y<=x;y++){ System.out.print("*"); } System.out.println(""); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { displayNumbersBetween(5,7); } private static void displayNumbersBetween(int start,int end){ if(start > end){ return ; } else { for(int x=1;x<=start;x++){ System.out.print("*"); } System.out.println(""); displayNumbersBetween(start+1,end); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { displayNumbersBetween(2,10); } private static void displayNumbersBetween(int start,int end){ if(start > end){ return ; } else { System.out.println(start); displayNumbersBetween(start+1,end); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { System.out.println(multiply(2,5)); } private static int multiply(int start,int end){ if(start > end){ return 1; } else { return start * multiply(start+1,end); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { System.out.println(sum(2,10)); } private static int sum(int start,int end){ if(start > end){ return 0; } else { return start + sum(start+1,end); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { System.out.println(factorial(5)); } private static int factorial(int number){ if(number == 1){ return 1; } else { return number * factorial(number - 1); } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly do excellence then is not an act but a haBit"; Set<String> wordSet = new TreeSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order for(String word: str.split(" ")){ wordSet.add(word); } for(String word: wordSet){ System.out.print(word); System.out.print(" "); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; Set<String> wordSet = new LinkedHashSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order for(String word: str.split(" ")){ wordSet.add(word); } for(String word: wordSet){ System.out.print(word); System.out.print(" "); } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; String str2 = "we are what we repeatedly Do is"; String[] str1Words = str1.split(" "); String[] str2Words = str2.split(" "); Set str1WordsSet = new HashSet(); for(String word:str1Words){ str1WordsSet.add(word); } int commonWordsCount = 0; for(String word:str2Words){ if(str1WordsSet.contains(word)){ commonWordsCount++; } } System.out.println(commonWordsCount); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; String str2 = "we are what we repeatedly Do is"; String[] str1Words = str1.split(" "); String[] str2Words = str2.split(" "); Set str1WordsSet = new HashSet(); for(String word:str1Words){ str1WordsSet.add(word); } for(String word:str2Words){ if(str1WordsSet.contains(word)){ System.out.println(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; for(String word:str.split(" ")){ if(word.length() > 2 && word.endsWith("it")){ System.out.println(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; for(String word:str.split(" ")){ if(word.length() > 2 && word.charAt(2) == 'p'){ System.out.println(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; for(String word:str.split(" ")){ if(word.contains("ha")){ System.out.println(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; for(String word:str.split(" ")){ if(word.startsWith("w")){ System.out.println(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; Set<String> words = new HashSet(); for(String word:str.split(" ")){ if(words.contains(word)){ System.out.println(word); } else { words.add(word); } } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread1 { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; System.out.println(str.split(" ").length); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; String wordWithFirstCaptalChar = ""; for(String word:str.split(" ")){ if(Character.isUpperCase(word.charAt(0))){ wordWithFirstCaptalChar = word; } } System.out.println(wordWithFirstCaptalChar); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly do excellence, then, is not an act but a haBit"; String wordWithCaptalChar = ""; for(String word:str.split(" ")){ if(!word.equals(word.toLowerCase())){ wordWithCaptalChar = word; } } System.out.println(wordWithCaptalChar); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread1 { public static void main(String args[]) { String str = "We are what we repeatedly do excellence, then, is not an Act but a habit"; int count = 0; for(Character c: str.toCharArray()){ if(Character.isLowerCase(c)){ count++; } } System.out.println(count); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "We are what we repeatedly do excellence, then, is not an Act but a habit"; int count = 0; for(Character c: str.toCharArray()){ if(Character.isUpperCase(c)){ count++; } } System.out.println(count); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly do excellence, then, is not an Act but a habit"; int count = 1; for(Character c: str.toCharArray()){ if(Character.isUpperCase(c)){ break; } else { count++; } } System.out.println(count); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Introduced with java 8 , Method References help us to point to methods by their name. A method references is described using :: symbol | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { for(int number=1;number < 100;number++){ boolean perfectNumber = true; for(int x=2;x<number;x++){ if(number % x == 0){ perfectNumber = false; } } if(perfectNumber){ System.out.println(number); } } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class BuggyBread { public static void main(String args[]) { int number = 7; boolean perfectNumber = true; for(int x=2;x<number;x++){ if(number % x == 0){ perfectNumber = false; } } if(perfectNumber){ System.out.println("Perfect Number"); } else { System.out.println("Not a Perfect Number"); } } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. && - AND || - OR ! - LOGICAL NOT | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. boolean byte char double float int long short void | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. https://qr.ae/TWK2Ok | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1. Object Level Reuse - private methods 2. Class Level Reuse - static methods 3. package level Reuse - default methods 4. Application Level Reuse - Classes 5. Multiple Applications Level Reuse - Libraries , Frameworks | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() ![]() | ||||