Java code taking input is taking a long time to execute -


import java.util.*; public class main {     public static void main(string [] args){         scanner input = new scanner(system.in);         int x = input.nextint();         int sum = 0;             for(int = 1; <= x ; ++){                 if(x % ==0){                 sum += ;                 }             }         system.out.println ("the sum of factors " + sum);     } } 

the program supposed take in number , print out sum of factors. however, hanging. replaced input code simple (int x=10) code , got desired answer (18).

this never finish executing until ctrl+d, because input here system.in, technically doesn't have end "out-of-the-box":

new scanner(system.in); 

Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -