Write a program to calculate the following
i want a Java program for this condition
1+4+9+16+….+100

Like this (1^2+2^2)

Hint use function pow(a,b)

Answer Posted / sandeep

public class calc{

public int square(int a)
{
return a*a;
}

public static void main(String args[]){
int i=1,sum=0;
calc obj = new calc();
for(i=1;i<=10;i++)
sum=sum+obj.square(i);
System.out.println("answer ="+sum);
}
}

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

which book we learned this mantis? how many version are realsed this mantis upto now?

1632


Explain three modes in which files can be accessed from python program

1512


could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?

1505


how to convert hashmap to arraylist with iteration

1418


When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)

926


there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box. eg: 3 box contain stick as:1,1,1. if u take 1 stick from 3rd numbred box you will any how win the match.

2612


which worker is involved in all the phases of SDLC?

1897


kindly send interview materials

1486


Write a program to find whether a given number is prime or not.

784


What is diffrent between Method and and function in c#

1742


1.what is the vesition managment.

1902


write the a cl program with the following specification A. Accept 2 parameters-date and date type B. if date type is J then convert date to *MDY format C. if date type is M convert date to *JUL format 4.send a program message with the value of converted date Please explain for each with coding?

2384


4. What is the need of START 0? Instead if can we use any other numeric? If we use what will happen?

2115


How to use string functions in QTP?give some examples

7422


iam confused to choose among testing, .net and java can anybody help me????????

1825