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 |
if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008
sample code for data transfer between two r/2 systems and r/3 systems?
What is the difference between WebIntelligence and Designer in creating universes?
what is the use of occurs 10 or (any number) in the internal table declaration with header line.
In Java what is the difference between following two statements ? int a[],b; int []a,b;
Explain three modes in which files can be accessed from python program
how to generate dsnless connectivity in j2ee
< DL Compact > tag is used for
How many packages available in java??
what is dynamic polymorphism?
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.
what is programming language?