answersLogoWhite

0

// 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

16y ago

What else can I help you with?

Continue Learning about Engineering

What is the answer of write a program which read no N and then generate 54321012345?

To generate the sequence "54321012345" based on an input number ( N ), you can write a simple program that first counts down from ( N ) to 0, then counts back up to ( N ). Here's a Python example: N = int(input("Enter a number: ")) result = ''.join(str(i) for i in range(N, -1, -1)) + ''.join(str(i) for i in range(1, N + 1)) print(result) When you input ( N = 5 ), this program will output "54321012345".


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 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.


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?

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


What is the answer of write a program which read no N and then generate 54321012345?

To generate the sequence "54321012345" based on an input number ( N ), you can write a simple program that first counts down from ( N ) to 0, then counts back up to ( N ). Here's a Python example: N = int(input("Enter a number: ")) result = ''.join(str(i) for i in range(N, -1, -1)) + ''.join(str(i) for i in range(1, N + 1)) print(result) When you input ( N = 5 ), this program will output "54321012345".


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.


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);


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

without understanding the program giving a input


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; }


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 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.


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


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

create a program that can input 100 names