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

how CLR identify vb file?

0 Answers   Tech Mahindra,


Differevce between arrays and array builders?

0 Answers  


how can i create report in abap to insert data in table pa0002 using insert command

0 Answers  


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?

1 Answers   Syntel,






how we can call xml file in java file using Android platform?

2 Answers   TCS,


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

0 Answers   Peerless,


shall we execute our java programmes in jre

0 Answers  


Info for guidewire documents and interview questions

1 Answers  


what is runtime exception and compiletime exception ?

1 Answers   Accenture,


What is Meaning of Windows Application & the use of Windows Applications? with Description.

1 Answers  


Hi All, Can any one please send me the difference between informatica 7i and 8i versions, Thanks in advance. vinod

0 Answers  


Categories