Tag: technology

Questions Related to technology


var one = ["a", "b"];       
var two = ["c", "d"];       
var three = one.concat(two);        alert(three);       

  1. abcd

  2. a,b,c,d

  3. c,d,a,b

  4. error


Correct Option: B

var one = ["a", "b"];
alert(one.join("&&"));      

  1. a&&b

  2. ab&&

  3. a,b,&&

  4. error


Correct Option: A

var one = ["a", "b", "c"];          
one.pop();          
alert(one);     

  1. a,b

  2. b,c

  3. error

  4. a,b,c


Correct Option: A

What is the output of the below JavaScript?


var one = ["a", "b", "c", "d"];         
alert(one.slice(-2));       

  1. error

  2. a,b

  3. a,b,c,d

  4. c,d


Correct Option: D

Given:

public static void before() {
    Set set = new TreeSet();
    set.add("2");
    set.add(3);
    set.add("1");
    Iterator it = set.iterator();
    while (it.hasNext())    System.out.print(it.next() + " ");
}

Which statements are true?

  1. The before() method will print 1 2

  2. The before() method will print 1 2 3

  3. The before() method will print three numbers, but the order cannot be determined

  4. The before() method will not compile

  5. The before() method will throw exception at runtime


Correct Option: E

AI Explanation

To determine the statements that are true, let's analyze the given code:

public static void before() {
    Set set = new TreeSet();
    set.add("2");
    set.add(3);
    set.add("1");
    Iterator it = set.iterator();
    while (it.hasNext())    System.out.print(it.next() + " ");
}

The code creates a TreeSet named set, which is a sorted set that does not allow duplicate elements. It then adds three elements to the set: the string "2", the integer 3, and the string "1".

The code then creates an iterator named it and iterates over the elements in the set using a while loop. Inside the loop, it prints each element followed by a space.

Based on the code logic and the behavior of TreeSet, let's evaluate each statement:

A. The before() method will print 1 2

This statement is incorrect. The TreeSet orders elements in ascending order. In this case, "1" will be printed before "2" because strings are ordered lexicographically. Therefore, the correct output would be "1 2 3", not "1 2".

B. The before() method will print 1 2 3

This statement is correct. As explained above, the TreeSet orders elements in ascending order, so the correct output would be "1 2 3".

C. The before() method will print three numbers, but the order cannot be determined

This statement is incorrect. The TreeSet orders elements in ascending order, so the order of the elements can be determined.

D. The before() method will not compile

This statement is incorrect. The code does not contain any compilation errors.

E. The before() method will throw an exception at runtime

This statement is correct. The code attempts to add elements of different types (a string and an integer) to the TreeSet. However, TreeSet requires the elements to be mutually comparable. Since the elements are not of the same type or mutually comparable, a ClassCastException will be thrown at runtime.

Therefore, the correct statements are:

B. The before() method will print 1 2 3 E. The before() method will throw an exception at runtime

The correct answer is E.

Given:


import java.util.*;   
public class Magellan {   
  public static void main(String[] args) {   
    TreeMap myMap = new TreeMap();   
    myMap.put("a", "apple"); myMap.put("d", "date");   
    myMap.put("f", "fig"); myMap.put("p", "pear");   
    System.out.println("1st after mango: " +   // sop 1  
       myMap.higherKey("f"));  
     System.out.println("1st after mango: " +   // sop 2  
       myMap.ceilingKey("f"));  
     System.out.println("1st after mango: " +   // sop 3  
       myMap.floorKey("f"));  
     SortedMap sub = new TreeMap();  
     sub = myMap.tailMap("f");  
     System.out.println("1st after mango: " +   // sop 4  
       sub.firstKey());  
   }  
 }

Which of the System.out.println statements will produce the output 1st after mango: p?

  1. sop 1

  2. sop 2

  3. sop 3

  4. sop 4

  5. compilation fails


Correct Option: A
Explanation:

To solve this question, we need to understand the methods used in the given Java code. TreeMap is a class that implements the Map interface using a tree structure. It stores key-value pairs in a sorted order. The methods used in the given code are:

  • higherKey(Object key): Returns the least key strictly greater than the given key, or null if there is no such key.
  • ceilingKey(Object key): Returns the least key greater than or equal to the given key, or null if there is no such key.
  • floorKey(Object key): Returns the greatest key less than or equal to the given key, or null if there is no such key.
  • tailMap(K fromKey): Returns a view of the portion of this map whose keys are greater than or equal to fromKey.

Now, let's go through each option and determine which one will produce the output "1st after mango: p":

A. sop 1: This statement calls the higherKey() method on the TreeMap object with the argument "f". This returns the least key strictly greater than "f", which is "p". The output of this statement will be "1st after mango: p". Therefore, option A is correct.

B. sop 2: This statement calls the ceilingKey() method on the TreeMap object with the argument "f". This returns the least key greater than or equal to "f", which is "f" itself. The output of this statement will be "1st after mango: f". Therefore, option B is incorrect.

C. sop 3: This statement calls the floorKey() method on the TreeMap object with the argument "f". This returns the greatest key less than or equal to "f", which is "f" itself. The output of this statement will be "1st after mango: f". Therefore, option C is incorrect.

D. sop 4: This statement creates a new TreeMap object named sub using the tailMap() method on the existing TreeMap object myMap. The tailMap() method returns a view of the portion of this map whose keys are greater than or equal to "f". The sub.firstKey() method returns the first key in the sub map, which is "f". The output of this statement will be "1st after mango: f". Therefore, option D is incorrect.

E. compilation fails: There are no compilation errors in the given code. Therefore, option E is incorrect.

The Answer is: A. sop 1

Given:

import java.util.regex.*;   
public class Archie {   
  public static void main(String[] args) {   
    Pattern p = Pattern.compile(args[0]);   
    Matcher m = p.matcher(args[1]);   
    int count = 

    while(m.find())  
       count++;  
     System.out.print(count);  
   }  
 }

And given the command line invocation:
java Archie "\d+" ab2c4d67 What is the result?

  1. 0

  2. 3

  3. 4

  4. 8

  5. 9


Correct Option: B

AI Explanation

To determine the result of the given command line invocation, let's go through the code step by step:

  1. The Pattern.compile(args[0]) line compiles the regular expression passed as the first command line argument ("\d+" in this case) into a pattern.

  2. The Pattern.matcher(args[1]) line creates a matcher object that matches the given input string ("ab2c4d67" in this case) against the pattern.

  3. The variable count is initialized to 0.

  4. The while(m.find()) loop executes as long as there is a match for the pattern in the input string. Each time a match is found, the loop body is executed.

  5. Inside the loop, the count++ statement increments the value of count by 1 for each match found.

  6. After the loop finishes, the value of count is printed using System.out.print(count).

Now, let's analyze the given input string "ab2c4d67" and the regular expression "\d+":

  • The regular expression \d+ matches one or more digits.

  • In the input string "ab2c4d67", there are 3 occurrences of one or more digits: 2, 4, and 67.

Therefore, the correct answer is B. The result printed by the program will be 3.

Whats ICONV?

  1. Converts string to user defined format.

  2. Converts string to internal storage format.

  3. Converts internal storage format to String.

  4. None of the above


Correct Option: B