Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new

 Categories >> Software >> Java Related >> Java J2EE >> Advanced Java

 Core Java Interview Questions (1721) Advanced Java Interview Questions (331) Swing Interview Questions (44) EJB Interview Questions (134) Servlets Interview Questions (255) Struts Interview Questions (196) JDBC Interview Questions (187) JMS Interview Questions (9) SunOne Interview Questions (3) J2EE Interview Questions (71) Weblogic Interview Questions (146) Websphere Interview Questions (14) Java Networking Interview Questions (20) Java J2EE AllOther Interview Questions (87)
Question
```Write a java program to find out the sum of harmonic series :
1 + ½ + 1/3 + ……… up to nth term , for any value of n.```
I also faced this Question!!     Answer Posted By

# 1
import java.io.*;
class Hermonic{
public static void main(String args[]){
double result = 0.0;
int num=0;
try{
System.out.println("Enter a term which you want to sum:");
}
catch(Exception e){}
while(num > 0){
result = result +( (double) 1 / num);
num--;
}
System.out.println("Output of Harmonic Series is "+result);
}
}

 Is This Answer Correct ? 2 Yes 0 No
Sourav Dey

# 2

import java.math.BigDecimal;
import java.math.RoundingMode;

public class GeneralJava {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println(new GeneralJava().process
(10));
}

private double process(int n) {

BigDecimal retVal = BigDecimal.ZERO;

for (int i=1; i<= n; i++) {

BigDecimal.ONE.divide(BigDecimal.valueOf(i),10,
RoundingMode.HALF_UP);

}

return retVal.doubleValue();
}
}

 Is This Answer Correct ? 4 Yes 3 No
S

  Question Asked @ Answers Other Advanced Java Interview Questions what is the proxy pattern? 1 What is UniCastRemoteObject and what is its use in RMI? 5 1) which method of the RequestDispatcher cannot be called once the output is sent to the client? a. forward b. include c. both a&b 2) which interface should an object implement to get notified of changes to the list of active sessions in a web application? a. HttpSessionListener b. HttpSessionActivationListener c. HttpSessionAttributeLIstener 3) A user can select multiple locations from a list box on an HTML form, which of the following methods can be used to retrieve all the selected location? a. getParameter() b. getParameterValues() c. getParamValues() 4) which of the following methods should be used to send character text to the client? a. ServletResponse.getWriter() b. ServletResponse.getOutputStream() c. ServletResponse.getOut() 5) which implicit object is always available in a JSP page? a. exception b. session c. out 6) which inclusion mechanism doesn't include the source of the page, rather the output of the page. a. include directive b. jsp:include action c. Bothe a& b 7) which attribute of the page controls whether a page participates in session or not? a. session-allowed b. session c. isSession 1 To make an object to begin executing as a separate thread, what method is used? 2 What is source and listener? 1 the advantages of polymorphic 1 what is DGC? 1 When you will synchronize your code? 2 what is difference between object state and behaviour? 2 Why JDBC has introduced 3 how we can implement interface in jsp ? Google 2 What is a layout manager? 1 For more Advanced Java Interview Questions Click Here