java - Terminating a user input determined Scanner? -
i wonder if explain why scanner keeps waiting on input? have stop process on eclipse before code block executes , unsure why scanner keep taking input day. expect press enter , code execute after entering x amount of numbers.
public static void main(string[] args){ scanner ascanner = new scanner(system.in); int sum = 0; system.out.println("enter ints : "); while(ascanner.hasnextint()){ sum += ascanner.nextint(); } system.out.println(sum); }
if want program take x amount of numbers, have counter , break while loop after has executed x number of times. alternatively, use loop make things easier.
you use ctrl+z in eclipse stop console waiting inputs.
Comments
Post a Comment