Thursday
April 24, 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 ...
programming - I am supposed to modify this program so it begins by asking the ...
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 ...
Math - Sum of 2 consecutive integers is 59. Write an equation that models that ...
Reply to grant about a regression problem - This is a reply to the question ...

Search
Members