onlinesoumitra
BAN USER- 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 in India| Report Duplicate | Flag | PURGE
Infosys Analyst Java - 1of 1 vote
AnswersWrite a program to remove duplicates from array of prime numbers.
- onlinesoumitra in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
Answerswrite a class which exposes only 20 of its Objects containing two methods borrowObject and returnObject .Code must be thread safe.Also write a method to get the number of Live Objects(Objects currently in use by other classes).
- onlinesoumitra in United States| Report Duplicate | Flag | PURGE
Samsung Developer Program Engineer Java
The code will look like this.But the problem is even after calling the returnObject the client class can keep on using the Object.I am still thinking on a fullproof code.
class TwentyOnly{
private static List<TwentyOnly> twenty= new ArrayList(20);
private static int counter=0;
private TwentyOnly(){
}
public static synchronized TwentyOnly borrow(){
if(counter<20){
twenty.add(0,new TwentyOnly());
counter++;
return twenty.get(0);
}
throw new RUntimeException("All Allowed instances allowed");
}
public static synchronized void returnObject(TwentyOnly t){
twenty.remove(t);
counter--;
}
}
But if >= returns true how the other <= can return false if it is comparing the two integer values?
- onlinesoumitra May 10, 2014