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 |
how CLR identify vb file?
Differevce between arrays and array builders?
how can i create report in abap to insert data in table pa0002 using insert command
you have a computer with 80GB hard disk and ubuntu 8.04 is installed on entire hard disk.now you have to create a seprate partition for windows OS and install win XP as dual boot.write down the steps involved along with the commands
1 Answers Anand Group, Indian Navy, TCS,
There are 3 jars containing two types of round marbles. One jar contains only red marbles, one jar contains only blue marbles and the third jar contains a mix of both red and blue marbles. Although the jars are labeled “red”, “blue” and “mixed” – all the jars are mislabeled. How many marbles would you have to pull out, and out of which jars, to find out how to fix the labels correctly?
how we can call xml file in java file using Android platform?
Explain three modes in which files can be accessed from python program
shall we execute our java programmes in jre
Info for guidewire documents and interview questions
what is runtime exception and compiletime exception ?
What is Meaning of Windows Application & the use of Windows Applications? with Description.
Hi All, Can any one please send me the difference between informatica 7i and 8i versions, Thanks in advance. vinod