Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

What will be the output of the code given below?

Assumption: LinkedList class is already implemented with all the required methods.

public class Tester {


public static void main(String args[]) {
LinkedList list = new LinkedList();
list.addAtEnd("11");
list.addAtEnd("13");
list.addAtEnd("18");
list.addAtEnd("34");
list.addAtEnd("46");
operate(list);
list.display();

public static void operate(LinkedList list ) {


Node temp = list.getHead();
while (temp.getNext().getNext() != null) {
temp.setData(temp.getNext().getData());
temp = temp.getNext();
}
}
}

What will be the output of the code given below?

Assumption: Stack class is already implemented with all the required methods.

public class Tester {


public static void main(String args[]) {
Stack stack = new Stack(10);
stack.push(18);
stack.push(10);
stack.push(24);
stack.push(56);
stack.push(27);
operate(stack);
stack.display();

public static void operate(Stack stack) {


for (int i = 0; i <= 2; i++) {
if (stack.pop() % 3 == 0) {
int temp = stack.pop();
stack.push(++temp);
stack.push(++temp);
}
}
}
}
What will be the output of the code given below?

Assumption: Stack class is already implemented with all the required methods.

public class Tester {


public static void main(String args[]) {
Stack stack = new Stack(10);
stack.push(11);
stack.push(19);
stack.push(18);
stack.push(20);
stack.push(15);
stack.push(13);
stack.push(17);
System.out.println(operate(stack));

public static int operate(Stack stack) {


int value = 0;
while (!stack.isEmpty()) {
if (stack.peek() % 2 != 0) {
value += stack.pop();
stack.pop();
} else {
stack.pop();
}
}
return value;

}
}

What will be the output of the code given below?

Assumption: Queue class is already implemented with all the required methods.

public class Tester {


public static void main(String args[]) {
Queue queue = new Queue(10);
operate(queue);
queue.display();
}

public static void operate(Queue queue) {


int[] numbers = { 12, 18, 17, 16, 28, 34, 36 };
int count = 6;
for (int number: numbers) {
if (count == 0) {
break;
}
if (number%count == 0) {
queue.enqueue(number);
}
--count;
}

}
}

What will be the output of the code given below?

public class Tester {


public static void main(String[] args) {
List<String> employees = new ArrayList<String>();
employees.add("Alex");
employees.add("Tom");
employees.add("Sam");
employees.add("john");
employees.add("Jack");
updateEmployee(employees);
for (String employee: employees) {
System.out.print(employee+" ");
}
}

public static void updateEmployee(List<String> employees) {


String[] newEmployees = { "John", "Jack", "Robert", "Steve" };
for (int counter = 0; counter <= newEmployees.length - 1;
counter++) {
if (!employees.contains(newEmployees[counter])) {
employees.add(counter + 1,
newEmployees[counter]);
}
}
}
}

What will be the output of the code given below?

public class Tester {

public static void main(String args[]) {


List<Integer> elements = new LinkedList<Integer>();
elements.add(1);
elements.add(2);
elements.add(3);
elements.add(4);
elements.add(5);
elements.add(6);
elements.remove(1);
elements.add(3, 34);
elements.set(5, 15);
System.out.println(elements);
}
}

Choose the correct option based on the execution of the code given below.

public class Tester {

public static void main(String args[]) {


List<Integer> elements = new LinkedList<Integer>();
elements.add(10);
elements.add(12);
elements.add(33);
elements.add(44);
elements.add(75);
elements.add(67);
int temp = 0;
int sum = 0;
for (int element : elements) {
temp = element;
while (temp != 0) {
sum += temp % 10;
temp = temp / 10;
}
if (sum % 2 == 0) {
System.out.println("Infosys");
}
}

}
}

What will be the output of the code given below?

public class Tester {


public static void main(String[] args) {
Set<String> linkedHashSet = new LinkedHashSet<String>();
linkedHashSet.add(new String("A"));
linkedHashSet.add(new String("B"));
linkedHashSet.add(new String("C"));
linkedHashSet.add(new String("C"));
linkedHashSet.add(new String("E"));
linkedHashSet.add(new String("D"));
linkedHashSet.add(new String("E"));
linkedHashSet.add(null);
linkedHashSet.add(new String("E"));
Object[] elements = linkedHashSet.toArray();
for (Object element : elements)
System.out.print(element + " ");
}
}

 
What will be the output of the code given below?

public class Tester {


public static void main(String[] args) {
Set<String> treeSet = new TreeSet<String>();
treeSet.add(new String("A"));
treeSet.add(new String("B"));
treeSet.add(new String("C"));
treeSet.add(new String("C"));
treeSet.add(new String("E"));
treeSet.add(new String("D"));
treeSet.add(new String("a"));
treeSet.add(new String("F"));
Object[] elements = treeSet.toArray();
for (Object element : elements)
System.out.print(element + " ");
}
}

Choose the correct option based on the execution of the code given below.

public class Tester {


public static void main(String args[]) {
Map<String, Integer> studentDetails = new HashMap<String,
Integer>();
studentDetails.put("Max", 337);
studentDetails.put("Stocks", 480);
studentDetails.put("Malinda", 570);
studentDetails.put("Mathew", 640);
studentDetails.put("Max", 340);
if (studentDetails.replace("stocks", 480, 650)) {
studentDetails.remove("Max");
} else {
studentDetails.put("Sam", 490);
}

System.out.println(studentDetails);
}

What will be the output of the code given below?

public class Tester {


public static void main(String args[]) {
Map<Integer, Integer> hashMap = new HashMap<Integer,
Integer>();
for (int counter1 = 0; counter1 <= 5; counter1++) {
for (int counter2=5; counter2>=1; counter2--) {
hashMap.put(counter1,counter2);
}
}
System.out.println(hashMap);
}
}
Choose the correct option based on the execution of the code given below.

public class Tester {


public static void main(String[] args) {
Deque<String> brands = new ArrayDeque<String>();
brands.add("Apple");
brands.add("Samsung");
brands.add("One Plus");
brands.add("Nokia");
brands.add("Blueberry");
brands.poll();
brands.add("Microsoft");
brands.element();
brands.peek();
brands.remove();
for (String brand: brands) {
System.out.println(brand);
}
}
}

Which of the asymptotic notations is used to represent the best-case analysis of an algorithm?

What is the time complexity of the code given below?

int number1 = 0, counter = 10;


while (counter > 0) {
number1+=counter;
counter/=2;
}

What is the best-suited condition for using linear search algorithm?

Consider an array, arr ={12,16,17,19,23,35,40}.

How many iterations are required to search 23 using binary search algorithm?

What is the time complexity of bubble sort algorithm?

Which of the given algorithmic approach tries to achieve a localized optimum solution?

8288006316

ANCHAL SINGH

(KB5005033)

You might also like