Monday
December 22, 2014

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 ...
Java - I am supposed to convert a program i already made into a Java console ...
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 Programming - Java Programming Question: basically want to keep the ...
VBScript - Option Explicit Dim Answer Dim aScores() Dim intNumScores ' ...
computer science - Writing a c++ program that stores the following values in ...
Integers - Suppose a1, a2, . . . , an is a list of n numbers with the following ...
Java Programming - I'm new to Java and I'm not sure how to write the source code...

Search
Members