Important Java Interview Question

Ads
 

Important Java Interview Question

Complete the Solver constructor so that a call to solveAll return a list with 2 values including the square root and the inverse of the integer passed as parameter.

public interface MathFunction { double calculate(double x); }

public class Solver {

private List<MathFunction> functionList; 

public Solver() {

// Complete here

} 

public List<Double> solveAll(double x) { 
    List<Double> result = new ArrayList<Double>(); 

    for (MathFunction function : this.functionList) { 
        result.add(new Double(function.calculate(x))); 
    } 

    return result; 
}

}

View Answers

June 8, 2012 at 3:26 PM

The given code accept a given value of double type and determine the square root of that number. Moreover, it also find the inverse of the given number. Both results will get store into the list.

import java.util.*;

public class Solver {
public Solver() {

List<Double> list=solveAll(25);
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
} 

public  List<Double> solveAll(double x) { 
    List<Double> result = new ArrayList<Double>(); 

    result.add(new Double(Math.sqrt(x)));
    double inverse=(double)1/x;
    result.add(new Double(inverse));

    return result; 
}
public static void main(String[]args){
    new Solver();
}

}

Ads









Related Tutorials/Questions & Answers:
Important Java Interview Question
Important Java Interview Question  Complete the Solver constructor so that a call to solveAll return a list with 2 values including the square root and the inverse of the integer passed as parameter. public interface
important topics to prepare for java interview
important topics to prepare for java interview  hi friends can anyone tell what are the important topics to prepare for java interview????   Each and every topic is important for an interview. You can find some
Advertisements
Java Interview Question
Java Interview Question  Java program Interview Question :i have a file which contains characters and integers in mixed format. for example :--> abd12 g156bcd etc Now how would i rearrange the file sothat the characters
Core Java Interview Question, Interview Question
Core Java Interview Question   ....   Core Java Interview Question Page 1 How could Java... to a file?      Core Java Interview Question Page 2
java interview question
java interview question  when will we use abstraction or interface
java interview question
java interview question  what is the usage of abstract class
Interview Questions - What are important features of Java?
Interview Questions - What are important features of Java?  Hi, What are important features of Java? Thanks   Hi, Being a popular Object Oriented programming language, Java comes with its most important feature. Its
Core Java Interview Question, Interview Question
Core Java Interview Question Page 2   .... Question: What comes to mind when you hear about a young generation in Java... mentions a shallow copy in Java? Answer: Object cloning. Question: If you're
Core Java Interview Question, Interview Question
Core Java Interview Question Page 12       Question: What is a transient variable? Answer... collections of objects. Question: How does Java handle integer overflows
Core Java Interview Question, Interview Question
Core Java Interview Question Page 32   ... Question: What is the ultimate ancestor of all java classes Answer: Object class is the ancestor of all the java classes Question: What
Interview Questions - What are important Java Language Elements?
Interview Questions - What are important Java Language Elements?  Hi, What are important Java Language Elements? Thanks   Hi, Java.... View all interview questions at Java Interview Questions with Answers page
Core Java Interview Question, Interview Question
Core Java Interview Question Page 4   ... is an important part of Java's security strategy. Garbage collection is also called... of the class object: Java- class-name.field-or-method-name Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 9       Question: What are the uses of Serialization... computer using such client/server Java technologies as RMI or socket programming
Core Java Interview Question, Interview Question
Core Java Interview Question Page 5       Question: What are different types... enterprise java beans. To send objects between the servers in a cluster. Question
Core Java Interview Question, Interview Question
Core Java Interview Question Page 14       Question: What is clipping? Answer: Clipping... that is implemented in a language other than Java. Question: Can a for statement loop
Core Java Interview Question, Interview Question
Core Java Interview Question Page 21       Question: How are the elements of a GridLayout... and are laid out using the squares of a grid. Question: What an I/O filter? Answer: An I
Core Java Interview Question, Interview Question
Core Java Interview Question Page 17       Question: What is the difference between... application window that can have a menu bar. Question: Which class is extended by all
Core Java Interview Question, Interview Question
Core Java Interview Question Page 7       Question: What... of java object into output stream, that stream can be file or byte array or stream
Java interview question
Java interview question  Hello i had an online test in some company...) You should only take into account one payment per payment id. 5) Important...-explanatory. All the clues/notes above are important :) 6) Your tasks: Provide
Core Java Interview Question, Interview Question
Core Java Interview Question Page 23       Question: To what value is a variable... and interfaces that are loaded by a Java program. Question: How does a try statement
Core Java Interview Question, Interview Question
Core Java Interview Question Page 22       Question: What is a compilation unit? Answer: A compilation unit is a Java source code file. Question: What interface
Core Java Interview Question, Interview Question
Core Java Interview Question Page 18       Question: Is &&= a valid Java operator? Answer: No, it is not. Question: Name the eight primitive Java
Core Java Interview Question, Interview Question
Core Java Interview Question Page 27       Modifiers Question: What are access modifiers... written in non java language Question: What are transient variables
Core Java Interview Question, Interview Question
Core Java Interview Question Page 26       Language Fundamentals Question: How... 64 - - Question: What types
Core Java Interview Question, Interview Question
Core Java Interview Question Page 16  ... implementation is deferred to a subclass. Question: How are Java source code files... and interfaces. Source code files use the .java extension. Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 15  ... is to provide access to the Java runtime system. Question: How many times may... takes an argument of the String[] type. Question: Which Java operator is right
java interview question
java interview question  class Test { void meth1() { System.out.println("meth1()"); meth2(); } static void meth2() { System.out.println("meth2()"); } public static void main
java interview question
java interview question  class Test { void meth1() { System.out.println("meth1()"); meth2(); } static void meth2() { System.out.println("meth2()"); } public static void main
Core Java Interview Question, Interview Question
Core Java Interview Question Page 20       Question: Name four Container classes. Answer: Window, Frame, Dialog, File Dialog, Panel, Applet, or ScrollPane Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 13       Question: What is an Iterator interface? Answer.... Question: What is the difference between the >> and >>> operators
Core Java Interview Question, Interview Question
Core Java Interview Question Page 19       Question: What is the difference between static... variables take on unique values with each object instance. Question: What

Ads