March 29, 2015

Homework Help: Computer Sciene-java

Posted by Lisa on Sunday, November 1, 2009 at 10:35pm.

Write a loop that will continuously prompt the user for integers to sum, -1 to exit. Sum these values and display the sum to the console.

Here is what I have so far, but I feel like I am missing something:

public class Sum1 {

public static void main (String [] args) {

Scanner in = new Scanner(;

final int Sentinel = -1;
int i;
int sum = 0;

System.out.println("Enter an integer:");
i = in.nextInt();

while(i != Sentinel) {

System.out.println("Enter an integer:");
i = in.nextInt();

sum = sum + i;

System.out.println("sum: " + sum + ".");




Answer this Question

First Name:
School Subject:

Related Questions

java - Write a java application that finds the smallest of several integers. ...
college math - I do not understand a problem from a text book or how to solve ...
Java - I am supposed to convert a program i already made into a Java console ...
Computer Programming - Java Programming Question: basically want to keep the ...
Reply to grant about a regression problem - This is a reply to the question ...
programming - I am supposed to modify this program so it begins by asking the ...
computer science - Writing a c++ program that stores the following values in ...
VBScript - Option Explicit Dim Answer Dim aScores() Dim intNumScores ' ...
programming - write a program that maintains two parallel arrays. after th ...
Integers - Suppose a1, a2, . . . , an is a list of n numbers with the following ...