Computer Science 202
Introduction to Programming
Fall 2013, The College of Saint Rose
Sum1To10 BlueJ Project
Click here to download a BlueJ project for Sum1To10.
Sum1To10 Source Code
The Java source code for Sum1To10 is below. Click on a file name to download it.
/* * Example Sum1To10: the use of a simple for loop to compute * the sum of the numbers 1 to 10. * * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012 * * $Id: Sum1To10.java 2228 2013-10-24 05:42:15Z terescoj $ */ import javax.swing.JOptionPane; public class Sum1To10 { public static void main(String[] args) { // initialize a variable for our running sum int sum = 0; // now have a for loop that counts 1-10, adding the value // of the counter to the sum inside each iteration of the loop for (int number = 1; number <= 10; number++) { sum += number; } // report the sum JOptionPane.showMessageDialog(null, "Our sum is " + sum); } }