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)
Answers were Sorted based on User's Feedback
public class Power {
public static void main(String[] args) {
int b=2;
for(int i=1;i<=10;i++)
{
System.out.println(Math.pow(i,b));
}
}
}
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / 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 |
Answer / sugumar
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ImprtntPrgrms;
/**
*
* @author user
*/
public class series {
public static void main(String args[]){
int i=1,sum=0;
series obj = new series();
for(i=1;i<=10;i++){
sum=sum+(i*i);
System.out.println("Values="+i*i);
}
System.out.println("Sum"+sum);
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mahavishnu
class Demo{
void check()
{
int a=0;
for(int i=1;i<=10;i++)
{
int b=i*i;
a=a+b;
System.out.println(a);
}
}
}
public class Newdemo
{
public static void main(String[] args)
{
Demo d=new Demo();
d.check();
}
}
Is This Answer Correct ? | 2 Yes | 3 No |
In staad pro, how can we design ROOF SLAB?
how can i apply validation without using errorprovider in C# windows application
HOW TO DOWNLOAD ORCUT SITE VIDEOS IN PC WITH THE HELP OF MOZILL'S FIREFOX?
what is the difference between a looping statement and a decision statement
Data structure used to impliment a menu:
WHAT IS MAIN IMPORTANT THING IN SOFTWARE?
How to swap values between two variables without using a third variable?
24 Answers HCL, TCS,
Is there any standard procedure to test the application as a whole? Or How can I test complete application right from the requirement gathering?
There is a table which contains all the employee details, unfortunately there is mistake occured while entering the data. ex: ------------------------------- empid empname gender address ------------------------------- 1 abcd f address1 2 defg m address2 3 ghth m address3 4 jkil f address4 write a update query that will change gender 'm' to 'f' and 'f' to 'm'
what are the advantages of sap on other software ?
5. How do you round the addition or subtraction of two numbers in assembler?
Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance