/* This is a program that asks the user for a positive integer n, and computes the sum of the squares of all numbers up to n. Laura Toma csci 101 */ public class SumSquares { public static void main (String args[]) { //set up reading from user ReadStream r = new ReadStream(); //read an integer from user int n; System.out.print("Please enter a positive integer: "); n = r.readInt(); r.readLine(); //assume n is indeed positive int i, sum; //sum will hold the sum i = 0; sum = 0; while (i <= n) { sum = sum + i*i; i = i+1; } System.out.println("Sum of squares of all numbers up to " + n + " is " + sum); System.out.println("Goodbye."); } //end of main } // end of class