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 | ||||
| ||||
Ans. public static void main(String[] args){ List<Integer> listOfIntegers = Arrays.asList(1,2,3,4,5,6,7,8,9,10,11); List<Integer> perfectAndPalindromeIntegers = new ArrayList<Integer>(); for(Integer i: listOfIntegers){ if(isPalindrome(i) && isPerfect(i)){ perfectAndPalindromeIntegers.add(i); } } System.out.println(perfectAndPalindromeIntegers); } private static Boolean isPalindrome(Integer i){ String str = String.valueOf(i); char[] charArray = str.toCharArray(); int x = 0; int y = str.length()-1; while(x < y){ if(charArray[x] != charArray[y]){ return false; } } return true; } private static Boolean isPerfect(Integer i){ for(int x=2;x<3;x++){ if(x*x == i){ return true; } } return false; } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
Related Questions | ||||
Difference between == and .equals() ? | ||||
Why is String immutable in Java ? | ||||
Explain the scenerios to choose between String , StringBuilder and StringBuffer ? or What is the difference between String , StringBuilder and StringBuffer ? | ||||
What are the difference between composition and inheritance in Java? | ||||
Explain OOPs or Explain OOPs Principles or Explain OOPs Concepts or Explain OOPs features or Tell me something about OOPs | ||||
What is a Lambda Expression ? What's its use ? | ||||
Why Char array is preferred over String for storing password? | ||||
What are different ways to create String Object? Explain. | ||||
Does garbage collection guarantee that a program will not run out of memory? | ||||
What is the difference between final, finally and finalize() ? | ||||