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

if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008

0 Answers  


sample code for data transfer between two r/2 systems and r/3 systems?

0 Answers  


What is the difference between WebIntelligence and Designer in creating universes?

0 Answers  


what is the use of occurs 10 or (any number) in the internal table declaration with header line.

0 Answers  


In Java what is the difference between following two statements ? int a[],b; int []a,b;

1 Answers  


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

0 Answers   Peerless,


how to generate dsnless connectivity in j2ee

0 Answers  


< DL Compact > tag is used for

0 Answers  


How many packages available in java??

7 Answers   CTS,


what is dynamic polymorphism?

2 Answers   Satyam,


Write a pseudo code to evaluate a number to any base given (2...16) based on the input. Number greater than 9 should be given as A-F for 10-15.

0 Answers   Goldman Sachs,


what is programming language?

2 Answers   TCS,


Categories