Monday
May 20, 2013

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(System.in);

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:
Answer:

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 ...
math URGENT!!!! - i have a list of 5 different numbers. the sum of 2 of the ...
VBScript - Option Explicit Dim Answer Dim aScores() Dim intNumScores ' ...
Computer Programming - Java Programming Question: basically want to keep the ...
Integers - Suppose a1, a2, . . . , an is a list of n numbers with the following ...
probability - two fair six-sided dice are rolled and the sum of the dots on the ...
math - find the sum of each of the following infinite series, if no sum, write ...
programming - Using Raptor, create a condition loop that will ask the user for ...
calculus - find the sum of the series: 1. the sum from n=1 to infinity of ((-1)^...

For Further Reading

Search
Members
Community