1 Replies - 457 Views - Last Post: 13 February 2013 - 03:25 PM Rate Topic: -----

#1 JoshAlex123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
(B) 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);
		System.out.println("Please enter a number");
		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  Icon User is offline

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

Reputation: 8378
  • View blog
  • 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
Please avoid double posting
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1