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



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

Answer / sumitpalsingh

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

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

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

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

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

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

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

Post New Answer

More Programming Languages AllOther Interview Questions

In staad pro, how can we design ROOF SLAB?

0 Answers   L&T,


how can i apply validation without using errorprovider in C# windows application

1 Answers  


HOW TO DOWNLOAD ORCUT SITE VIDEOS IN PC WITH THE HELP OF MOZILL'S FIREFOX?

0 Answers  


what is the difference between a looping statement and a decision statement

3 Answers  


Data structure used to impliment a menu:

0 Answers   Verifone,






WHAT IS MAIN IMPORTANT THING IN SOFTWARE?

0 Answers   Infosys,


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?

0 Answers  


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'

2 Answers  


what are the advantages of sap on other software ?

0 Answers  


5. How do you round the addition or subtraction of two numbers in assembler?

0 Answers   Wipro,


Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance

0 Answers  


Categories