I need to create a method which totals a series of positive integers which the user enters from the keyboard. The user will type in each value followed by an <Enter> keypress. After the last value the user will type a negative value: this is the terminal sentinel.
So far, the code which I have in the class Looping:
Code :public static void main(String[] args){ int count =0; int sum= 1; do { System.out.println(+ count + sum); count++; sum += count; }while(count <=4); } }
Code :import java.util.Scanner; /** * InputReader reads typed text input from the standard text terminal. */ public class InputReader { private Scanner reader; /** * Create a new InputReader that reads text from the text terminal. */ public InputReader() { reader = new Scanner(System.in); } /** * Accesses a String typed in text terminal * * @returns String value input */ public String getString() { String input = reader.nextLine(); return input; } /** * Accesses a int typed on a single line in text terminal * * @returns int value input */ public int getInt() { int input = reader.nextInt(); reader.nextLine(); return input; } }
