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

sample and simple coding where we get?

1784


Find out the roles which gives access to all tables in SAP? Thanks in advance.

1564


public static void main(String args[]) describe it

1578


I'm new to ABAP. What is Module pool in SAP?

2126


How to change the color of a cell or a row in a datagrid on mouse hover using javascript/.net

1537






the systematic access of small computers in a distributed data processing system is referred as?

2730


Which language they use during interview?

1523


Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number

729


how much fee for deccan soft institute .how to block seat for sandeep sir class reply soonnnn 

1661


Hi can you please help for the following. I have a ASP.Net web page I want to print the whole page how is it possible? I want It in ASP also.Please send me the solutions dipankar.hazari@gmail.com . Thanks in advance.

2327


When we have two versions of the dot net installed how does the compiler know which version of DLL it has to select to an application.

1431


Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad

1849


hi all, i need ur help in preparing a sql which performs scd2, i mean i have a scd2 mapping i need a sql which can give me same result as scd2 mapping, SRC table: cust_no, loc 01 abc 02 xyz TGT table: pm_ky cust_no loc current_flag 1 01 abc Y 2 02 xyz Y cust 1 has changed his loc to xyz then it loads into TGT table as below, pm_ky cust_no loc current_flag 1 01 abc N 2 02 xyz Y 3 01 xyz Y i need sql to get the above result, hope got me question, Any suggestion will be appreciate.. thanks, Vinod

1647


Given an array of size n, containing every element from 1 to n+1, except one. Find the missing element.

650


how to work search engine? plz detail answer me.

1491