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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -