Java Interview Questions
- 0of 0 votes
Answerswrite a java program consider a text file,that file is having N number of lines.how to print last N lines..
- Muni June 28, 2014 in India| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersLakshmi is a primary school teacher. She wants to give some laddus to the children in her class. All the students sit in a line and each of them has a rating score according to his or her usual performance. Lakshmi wants to give at least 1 laddu for each child. Children get jealous of their immediate neighbors, so if two children sit next to each other then the one with the higher rating must get more laddus. Lakshmi wants to save money, so she wants to minimize the total number of laddus.
- Anonymous June 15, 2014 in United States
Tip: Please understand the question clearly and pay good attention to below provide - sample input and output - completely in order to arrive at correct solution.
Input
The first line of the input is an integer N, the number of children in Lakshmi's class. Each of the following N lines contains an integer indicates the rating of each child.
Ouput
Output a single line containing the minimum number of laddus Lakshmi must give.
Explanation
Sample Input
3
1
2
2
Sample Ouput
4
Explanation
The number of laddus Lakshmi must give are 1, 2 and 1.| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersBase class is given you need to stop exposing the base class methods without touching the base class at all.
- hareendrareddy June 07, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Java - -2of 2 votes
AnswersThe boggle game - given a 2d array of characters
- FauxPas June 07, 2014 in United States| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java - 1of 1 vote
AnswersEvaluate a given mathematical expression, taking into consideration the BODMAS rule. The expression contains no brackets.
- FauxPas June 07, 2014 in United States| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java - 0of 0 votes
AnswersSerialize and deserialize a tree.
- FauxPas June 07, 2014 in United States
Given a tree - not necessarily a binary tree - the serialize method should create a string for the tree. The deserialize method should be able to reproduce the same tree using the string derived from the serialize method.
Basically, serialize() takes in a tree and returns a string, deserialize() takes in a string and returns the tree.| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm Coding Java Object Oriented Design - 0of 0 votes
AnswersString d1="7 dec 2012";
- alis June 06, 2014 in India
String d2="15 dec 2012";
String d3="12 dec 2012";
String d4="16 dec 2012";
String d5="16 dec 2012";
String d6="24 dec 2012";
days between d1 and d2 is: 9
days between d3 and d4 is: 1 (12 dec to 15 dec counted in d1 and d2, don't count overlapping days)
days between d3 and d4 is: 8 (16 dec counted in d3 and d4, don't count overlapping days)
now final output should be: 9 + 1 + 8=18| Report Duplicate | Flag | PURGE
Tricon Java Developer Java - 7of 7 votes
AnswersGiven a string (for example: "a?bc?def?g"), write a program to generate all the possible strings by replacing ? with 0 and 1.
- pennepalli May 30, 2014 in United States
Example:
Input : a?b?c?
Output: a0b0c0, a0b0c1, a0b1c0, a0b1c1, a1b0c0, a1b0c1, a1b1c0, a1b1c1.| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Algorithm C# C++ Java - 1of 1 vote
Answers
- ps May 27, 2014 in United StatesGiven the following directory structure: org | -- Robot.class | -- ex |-- Pet.class | |-- why |-- Dog.class And the following source file: class MyClass { Robot r; Pet p; Dog d; Which statement(s) must be added for the source file to compile? (Choose all that apply.) A. package org; B. import org.*; C. package org.*; D. package org.ex; E. import org.ex.*; F. package org.ex.why; G. package org.ex.why.Dog;
| Report Duplicate | Flag | PURGE
Software Engineer in Test Java - 0of 0 votes
AnswersHere is a small program which will be of my help.
- sharathchitra May 23, 2014 in India
Please code it in JAVA. If you are successful, please send me the code as early as possible by tomorrow.
If you are not able to get, please send me the update.
The Definition is given as below:
1. A File contains string for Example: GCDNPQACKSPEGF...FIM
2. Read each character from this file and ASSIGN the values as below:
A,C,S = 3
F,D,N,T= 4
P,F,Y = 9
M,E,G = 2
Q,H,I,K,R,L = 6
3. AFTER ASSIGNING CHECK THE FILE FOR MAPPING
4. Sum THE VALUES in that sequence for Eg: 2+ 3+ 4...... = SUM = 60
5. FIND THE total LENGTH of the sequence for E: L = 20
6. Find the AVERAGE A = SUM/L =60/20 =3
7. USE THE PATTERNS as triplets from the same file as given below AND CALCULATE EACH PATTERN'S WEIGHTAGE as for Eg:
GCD = 2 + 3 + 4 = 9 (G = 2, C=3, D=4 from the mapping)
CDN = 3+4+4 = 11
...........
for all possible patterns
8. FinD THE MAXIMUM OF ALL THE PATTERN'S WEIGHTAGE
So, the o/p should be : Average -->
Triplet and its Weightage as :GCD : 2 + 3+ 4 = 9 for all possible triplets
Maxi Weightage -->| Report Duplicate | Flag | PURGE
Student student Java Developer Java - 0of 0 votes
AnswersA matrix will be given which contains nos. and dots. will have to output another matrix in which the nos. are surrounded by single loop. the value of each number in a matrix equals the number of lines surrounding it.
- im.akki90 May 23, 2014 in India
Empty spaces in matrix/dots may be surrounded by any number of lines.
When completed, the solution forms a single continuous loop with no crossings or branches.
Value of each no. should connect the adjacent dots horizontally and vertically so that the lines form a simple loop with no loose ends based on the above rules.
eg
input Matrix
1.31.3
...3..
.3.21.
.02.1.
..2...
2.23.3
output Matrix
- -
1 .|3|1 .|3|
- - | - |
|. . .|3|. .|
| - - -
|.|3|. 2 1|.
- - - _
. 0 2 .|1 .|
- - - -
|.|.|2 . .|.
| - - -
|2 . 2|3|. 3|
- - - - -
i tried making rules and then call the function to make lines, but couldnt succeed in gettin desired output.
for any queries please comment| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Java - 0of 0 votes
AnswersA matrix will be given which contains nos. and dots. will have to output another matrix in which the nos. are surrounded by single loop. the value of each number in a matrix equals the number of lines surrounding it.
- im.akki90 May 23, 2014 in India
Empty spaces in matrix/dots may be surrounded by any number of lines.
When completed, the solution forms a single continuous loop with no crossings or branches.
Value of each no. should connect the adjacent dots horizontally and vertically so that the lines form a simple loop with no loose ends based on the above rules.
eg
input Matrix
1.31.3
...3..
.3.21.
.02.1.
..2...
2.23.3
output Matrix
- -
1 .|3|1 .|3|
- - | - |
|. . .|3|. .|
| - - -
|.|3|. 2 1|.
- - - _
. 0 2 .|1 .|
- - - -
|.|.|2 . .|.
| - - -
|2 . 2|3|. 3|
- - - - -
i tried making rules and then call the function to make lines, but couldnt succeed in gettin desired output.
for any queries please comment| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Java - 0of 0 votes
AnswersMultiple threads are running in my program. Exception occurs in one of the thread. There is no exception handling done.
- vijayinani May 23, 2014 in India
What will happen to my program? Will it terminate the complete program? What will happen to other threads?| Report Duplicate | Flag | PURGE
Credit Suisse Software Engineer / Developer Java - 0of 0 votes
Answersi) Explain Polymorphism
ii) Output of the below code snippet :-
- hulk May 15, 2014 in Indiapublic class ParentTest { public int x = 0; public void print() { System.out.println("In Parent"); } } public class ChildTest extends ParentTest { public int x = 1; public void print() { System.out.println("In Child"); } public static void main( String args[] ) { ParentTest s = new ChildTest(); System.out.println(s.x); s.print(); } }
| Report Duplicate | Flag | PURGE
Morgan Stanley Software Engineer / Developer Java - 0of 0 votes
AnswersIn synchronous request from browser how do you get results if you have to access 2 different databases
- cheeta May 14, 2014 in United States| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
AnswersIn assembly line situation, how do you pass a job from thread1 to thread2 to thread3?
- cheeta May 14, 2014 in United States| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
Answerin a web request you want to send results to the browser/client only if the caching operation goes success. how do you accomplish this.
- cheeta May 14, 2014 in United States| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
Answerspublic class Gen { public static void main(String[] args) { Integer i1 = new Integer(1); Integer i2 = new Integer(1); System.out.println(i1 != i2); System.out.println(i1 <= i2); System.out.println(i1 >= i2); } }
WHY THE OUTPUT IS TRUE IN ALL CASES?
- onlinesoumitra May 10, 2014 in India| Report Duplicate | Flag | PURGE
Infosys Analyst Java - 0of 0 votes
AnswersA non-empty zero-indexed array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A.
- Mehaboob557 May 03, 2014 in India
Write a function:
int arrLeader(int A[], int N);
int arrLeader(NSMutableArray *A);
int arrLeader(const vector<int> &A);
class Solution { int arrLeader(int[] A); }
class Solution { public int arrLeader(int[] A); }
function arrLeader(A);
function arrLeader(A)
function arrLeader($A);
function arrLeader(A : array of longint; N : longint) : longint;
def arrLeader(A)
sub arrLeader { my (@A)=@_; ... }
def arrLeader(a)
Private Function arrLeader ( A As Integer() ) as Integer
that, given a non-empty zero-indexed array A consisting of N integers, returns the leader of array A. The function should return -1 if array A does not contain a leader.
Assume that:
l N is an integer within the range [1..1,000,000];
l each element of array A is an integer within the range [0..2,147,483,647].
For example, given array A consisting of ten elements such that:
A[0] = 4 A[1] = 2 A[2] = 2 A[3] = 3 A[4] = 2 A[5] = 4 A[6] = 2 A[7] = 2 A[8] = 6 A[9] = 4
the function should return -1, because the value that occurs most frequently in the array, 2, occurs 5 times, and 5 is not more than half of 10.
Given array A consisting of five elements such that:
A[0] = 100 A[1] = 1 A[2] = 1 A[3] = 50 A[4] = 1
the function should return 1.
Complexity:
l expected worst-case time complexity is O(N);
l expected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).
Elements of input arrays can be modified.
// you can also use includes for example:
// #include <algorithm>
int arrLeader ( const vector<int> &A ) {
// write your code here
}| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersImplement multiple producer and multiple consumer problem in java.
- hulk May 03, 2014 in India| Report Duplicate | Flag | PURGE
Infibeam SDE-2 Java - 0of 0 votes
Answeri) Difference between HashMap & HashTable
- hulk April 26, 2014 in India
ii) How will you implement your own sorting algorithm in java?| Report Duplicate | Flag | PURGE
Collective Software Engineer / Developer Java - 1of 1 vote
AnswersInput will be a matrix consiting of only 1's n 0's.
- im.akki90 April 21, 2014 in India
The 1's represent the lines and 0's its absence.
For eg a matrix 6X7 is shown
0 0 0 1 1 1 1
0 1 1 1 0 1 1
0 1 0 1 0 1 1
0 1 0 1 0 1 1
0 1 1 1 0 1 1
0 0 0 1 1 1 1
In the above matrix, the sequence of 1’s represents the lines. These eight lines constitute three
rectangles.
Conditons :
1. The rectangles will always enclose some 0’s. e.g. last two vertical lines does not constitute a
rectangle.
2. A rectangle can contain multiple rectangles
Output : should be no. of rectangles formed in the matrix(intersecting rectangles are also counted).| Report Duplicate | Flag | PURGE
McAfee Senior Software Development Engineer Java - 1of 3 votes
AnswersGiven a number N, find the smallest even number E such that E > N and digits in N and E are same.
- jerinsebastian.punnamada April 08, 2014 in United States
Print NONE otherwise.
Sample:
Input
N = 34722641
Output
E = 34724126
Input
N = 8234961
Output
E = 8236194 (instead of 8236149)
Java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 1of 1 vote
AnswersGiven two words, determine if the first word, or any anagram of it, appears in consecutive characters of the second word. For instance, tea appears as an anagram in the last three letters of slate, but let does not appear as an anagram in actor even though all the letters of let appear in slate.
- jerinsebastian.punnamada April 08, 2014 in United States
Return the anagram of the first word that has appeared in the second word.
Sample Input 1
tea
slate
Sample Output1
ate
Sample Input 2
let
slate
Sample Output2
NONE
java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 1of 1 vote
AnswersGiven a string, complete the given function to recursively remove the adjacent duplicate characters and return the resultant string. If there are no characters left in the resultant string, return "-1" (without quotes).
- jerinsebastian.punnamada April 08, 2014 in United States
Sample Test Cases
Sample Input: ABCCBCBA
Output: ACBA
Explanation: (ABCCBCBA --> ABBCBA --> ACBA)
Sample Input: AA
Sample Output: -1
Java solution| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Algorithm Java - 0of 2 votes
AnswersClass A
- PKT April 06, 2014 in India
{ void print(){}
}
Class B extends A
{ void print(){}
public static void main(String args[])
{
B b = new A();
}
}
Whats wrong with the above piece of code?
will below mentioned line work?
B b = (B)new A();| Report Duplicate | Flag | PURGE
Citigroup Java - 0of 0 votes
AnswerUnable to get what exactly the Question Is?
- jsd.learner April 02, 2014 in India
so What is the whole logic behind this question .It seems to be complete Math problem to me.
There is a Grasshopper in a tropical forest. The grasshopper can jump only vertically and horizontally, and the length of jump is always equal to x centimeter. A GRasshopper has found herself at the center of some cell of the chess board of the size pxq centimeters(each cell is 1x1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. the only restriction is that she cannot jump out of the board.
The grasshopper can count the number of cells that she can reach from the starting position(x,y). Let's denote this amount by dx,y. your task is to find the number of such starting position(x,y), which have the maximum possible value of dx,y
Input
The integer array contains three integers p,q,x
p= length of the board
q= width of the board
x=length of the grasshoppers jump.
Output
Output the only integer - the number of the required starting position of the Grasshopper
Example
input 2 3 1000000
output 6
input 3 3 2
output 4
Regards,
JSD| Report Duplicate | Flag | PURGE
Algorithm Brain Teasers Ideas Java Knowledge Based Math & Computation - 0of 0 votes
AnswersWe can start a Thread using either of two methods start() and run().What is the difference between these two?
- searchingviswa March 15, 2014 in India for 100| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java
Open Chat in New Window