answersLogoWhite

0


Best Answer

// create an BufferedReader from the standard input stream

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String currentLine = "";

int total = 0;

// read integers

System.out.print("Input an integer: ");

while (!(currentLine = in.readLine()).equals("")) {

int input = 0;

try {

input = Integer.valueOf(currentLine);

total += input;

} catch (final NumberFormatException ex) {

System.out.println("That was not an integer.");

}

System.out.print("Input an integer: ");

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program that takes a list of all positive integers from input and counts as the integers are input?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

How do you write a program to print the first n multiples of 7?

Algorithm: multiples input: two positive integers, m and n output: print first n multiples of m i = m; for j = 1 to n print i i = i + m; next j


How do you write a program that asks a user to enter a list of integers placing positive and negative integers into separate arrays and output both arrays?

#include#include#include#includeusing namespace std;string ask(string prompt){string input;coutinput)return(input);return(0);}bool ask_yn(std::string prompt){while(1){string input = ask(prompt);if( input.size() && input.size()


What is legal input?

In a computer program, a legal input is something that can be put into a program and it will work. An illegal input may crash the program.


What is an adequate measure of the size of input for a program that requires two integer numbers n?

Not sure what you mean; if you want to measure the "input size" in bytes, that would probably be 8 bytes, since integers typically use 4 bytes.


Which is not a way to input data into a program?

without understanding the program giving a input


Write a Java Program that reads a line of integers and then displays each integer and the sum of all the integers Use StringTokenizer class of javautil?

// Get input BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input = in.readLine(); in.close(); // Parse input int sum = 0; StringTokenizer parser = new StringTokenizer(input); while (parser.hasMoreTokens()) { int currentInt = Integer.parseInt(parser.nextToken()); System.out.println(currentInt); sum += currentInt; } System.out.println("sum = " + sum);


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


How do you write a c program that counts number of blanks in a text file using standard io?

int count_whitespace (FILE* input) { int c, count=0; while (( c = getc(input) ) != EOF ) if ((char) c==' ') ++count; return count; }


How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


In a positive feedback system how does the output affect the input?

In a positive feedback system, the output increases the input.


How do you create a program that can input 100 names using flowchart?

create a program that can input 100 names


What is countering?

A counter is a sequencial circuit with a set of flip flop which counts the number of pulses given at the clock input A counter is a sequencial circuit with a set of flip flop which counts the number of pulses given at the clock input