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

Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

0 Answers   Mind Tree,


hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com

0 Answers  


write a query that returns one row for each department and the number of employees in that department. Given two tables EMPLOYEE and DEPARTMENT, where there can be multiple employees per department.

0 Answers   IBM,


what is the diffrence between software and hardware language?

0 Answers  


6.int x=10; float y=20; a=x%2=? b=y%2=?

1 Answers  






hi viewers, tell me,what is scripting and programming, define and difference...pls

0 Answers   Symphony,


pleasew define carrier scope in abap (sap).

0 Answers  


what do u mean by tagging

0 Answers  


why applet is introduced?

1 Answers  


1.Mutating table

0 Answers  


How can successful and thorough systems planning, analysis, and design be ruined by poor systems construction and implementation? How can poor systems analysis or design ruin a smooth construction and implementation? For both questions, list some consequences

1 Answers  


How many forms can you create in a Visual Basic 6 Standard EXE project? Is there any limit on that?

0 Answers  


Categories