# method function squares and sum of squares

Page 1 of 1

## 1 Replies - 478 Views - Last Post: 13 February 2013 - 03:25 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312167&amp;s=4577064cffa325c7813862905b03ebb1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 JoshAlex123

Reputation: 0
• Posts: 7
• Joined: 13-February 13

# method function squares and sum of squares

Posted 13 February 2013 - 03:20 PM

HI i have been given a task to write a program as follows:

Incorporate the function methods square and sumOfSquares into a Java program (need to call sumOfSquares
from main method).
(a) Amend so that the sum of squares from 1 to 10 (i.e. using the value n = 10) is output to screen.
( Amend your program so that the user is asked to input the value of n before sum of squares is output to
screen.
© Further amend your program so that the user is repeatedly asked to input a value for n (and the sum of
squares output to screen) until -1 is input, which terminates the program.

i have had several attempts at this and cant find a solution...

this is the code i have so far:
```public class sumofsquares
{

public static void main (String [] args)
{
int number, sum, square;
Scanner Key = new Scanner(System.in);
number = Key.nextInt();

}

public static int square(int n)
{
return n*n;
}

public static int sumofsquares(int n)
{
int sum = 0;
int i;
for (i = 1; i<= n; i++)
{
sum = i + square(i);
}
return sum;
System.out.println(+sum);

}
}

```

i am very new to java and could do with as much help as possible.

i have been trying for hours and nothing seems to work

Is This A Good Question/Topic? 0

## Replies To: method function squares and sum of squares

### #2 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: method function squares and sum of squares

Posted 13 February 2013 - 03:25 PM

Duplicated post closed