Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions Important Java Interview Question
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Manish
Important Java Interview Question
1 Answer(s)      2 years and 4 months ago
Posted in : Java Interview Questions


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; 
}

}


Advertisement
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();
}

}


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 and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Important Question
Important Question  Respected Sir, I am Sanjay Baniwal working in BHEL as a Software Developer as a trainee for One Year. And i have been given a Project in which i have to create a JSP page with a Drop Down List in which all
Interview question link - Java Beginners
Interview question link  Hi, I want JAVA+J2EE interview question and answer please suggesion me link
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
interview question - Java Interview Questions
interview question  hello i want technical interview question in current year   Hi Friend, Please visit the following links: http://www.roseindia.net/interviewquestions/ http://www.roseindia.net
java interview question
java interview question  what is the usage of abstract class
java interview question
java interview question  when will we use abstraction or interface
Important Interview Questions in Core Java
Important Interview Questions in Core Java Core Java refers... who are master in advanced java as whenever you go for the interview... questions. Mastering in Java is a different thing and facing an interview
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 Question - Java Interview Questions
Interview Question  I need Interview Questions on Java,J2EE Pls help me
Interview question - Java Interview Questions
Interview question   Hi Friends, I am new to java, can u tell me what is class ,object and instance with example. For example : class raja , raja r = new raja(); ,here raja is class and r is instance
Interview question - Java Interview Questions
Interview question   Hi Friends, Give me details abt synchronization in interview point of view. I mean ow to explain short and neat. Thanks
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
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 23       Question: To what value is a variable... and interfaces that are loaded by a Java program. Question: How does a try statement
Interview Question - Java Interview Questions
Interview Question  1)If we give S.O.P. statement after finally block shall it prints or not? 2)Write a program in java to read a file & write in to another file? 3)Write a program taking two arrays and compare those two
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 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 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
 

 

 

DMCA.com