Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
| ||||
Ans. 4567 5678 6789 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   set   treeset   coding   code | ||||
Ans. SUNDAY MONDAY SATURDAY | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  enum   set   collections   hashset   coding   code | ||||
Try 3 Question(s) Test | ||||
Ans. FRIDAY , SATURDAY and WEDNESDAY will be printed but the order cannot be determined. Only one FRIDAY will be printed as Set doesn't allow duplicates. Order cannot be determined as HashSet doesn't maintain elements in a particular order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   enum   set   hashset | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. 1 111 2 TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in String has been defined such that it results in the natural alphabetic Order. Here the elements in the TreeSet are of String and not of Integer. In String Natural Order, 111 comes before 2 as ascii of 1st character first determines the order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   set   treeset   string   integer | ||||
| ||||
Ans. 1 2 111 TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in Integer has been defined such that it results in the natural numerical Order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   set   treeset | ||||
| ||||
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body". | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no | ||||
| ||||
Ans. public static void main (String args[]) { String inputStr = "I am a boy, output: I1 am2 a1 boy3"; String splitStr[] = inputStr.split(" "); String outputStr = new String(); for(String str1: splitStr){ outputStr += str1 + str1.length() + " "; } System.out.println(outputStr); } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   coding | ||||
| ||||
Ans. First will give the ouput as 3 and the second will give output as 2 1 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   system.out.println   coding | ||||
| ||||
Ans. One. As we haven't specified the type of TreeSet, it being evaluated with the first element insertion. Once it's identified that it's of type String and as no comparator has been defined, the comparison is done using the String compareTo method. String compareTo method compares the elements by the content / value. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   set   treeset   string   compareto   coding   code | ||||
Ans. Compile time error at last line as the get method expect argument of type native int. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  arraylist   list   coding   collections | ||||
Ans. Yes but the last line will throw NullPointerException upon execution. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections   arraylist   list   coding | ||||
| ||||
Ans. truefalse | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   coding   equality   object equality | ||||
| ||||
Ans. 16 bits | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   character coding   character encoding | ||||
| ||||
Ans. http://stackoverflow.com/questions/18799591/print-natural-sequence-with-help-of-2-threads1-is-printing-even-and-2nd-is-pri | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  print natural numbers with two threads   multithreading   multi threading   threads   code   coding   makemytrip.com | ||||
| ||||
Ans. http://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/ | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  algorithm   program   code   coding  makemytrip.com | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+convert+all+elements+of+a+collection&category=code | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  code  coding  string  String.toLowerCase  set  collections | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=singleton+class&category=code | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  singleton  code  coding  design pattern Asked in 1 Companies Intermediate   frequent | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=946 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  code  coding  scanner basic | ||||
Very frequently asked to fresh graduates. Frequently asked in NSEiT and Accenture India | ||||
| ||||
Ans. public class Main { public static void main(String args[]) { int number = 2; int count = 0; long sum = 0; int givenNumber = 1000; while (count < givenNumber) { if (isPrimeNumber(number)) { sum = number; count; } number; } System.out.println(sum); } private static boolean isPrimeNumber(int number) { for (int i = 2; i <= number / 2; i) { if (number % i == 0) { return false; } } return true; } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  generate prime numbers  code  coding Asked in 5 Companies basic   frequent | ||||
| ||||
Ans. public class Factorial { public static void main(String[] args){ int x = 5; System.out.println(calculateFactorial(x)); } private static int calculateFactorial(int x){ if(x==1){ return 1; } return x * calculateFactorial(x-1); } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  factorial  calculate factorial  code  coding  recursion Asked in 1 Companies basic | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  builder design pattern  builder pattern  code  coding intermediate | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=965 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  constructor overloading  code  coding Asked in 2 Companies basic | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=963 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ternary operator  code  coding | ||||
| ||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=952 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  set  collections  sorting  treeset  code  coding | ||||
| ||||
Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  interfaces  abstract classes  code  coding | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. false false | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  object equality  code  coding   frequent | ||||
| ||||
Ans. There are many problems with the code 1. The method returns void and hence we cannot return any integer value. 2. We cannot return more than one value from a method. 3. The code after 1st Return statement is unreachable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  coding  code | ||||
| ||||
Ans. http://www.programmingsimplified.com/java/source-code/java-program-armstrong-number | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  program  code  coding  armstrong number Asked in 1 Companies | ||||
| ||||
Ans. package com.string; import java.util.Scanner; public class String13 { public static void main(String[] args) { System.out.println("Enter Sentence"); Scanner sc=new Scanner(System.in); String sentence=sc.nextLine(); String[] words=sentence.split(" "); int count=0; for (String string : words) { string.trim(); if(!string.equals("")){ count++; System.out.println(string " " count); } } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  code  coding Asked in 1 Companies | ||||
| ||||
Ans. int[] arr = {1,-1,2,-3,3,-4,4,5,6,-5,-6,-7,-8,8,9,-9}; List positiveNumbers = new ArrayList<>(); List negativeNumbers = new ArrayList<>(); for(int i = 0; i < arr.length(); i ){ if(I < 0){ negativeNumbers.add(i); } else { positiveNumbers.add(i); } } System.out.println("Positive Numbers:" + positiveNumbers); System.out.println("Negative Numbers:" + negativeNumbers); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  code  program  coding Asked in 1 Companies | ||||