For loop working in C# -


i writing program finds number of 1's in array.. "scanning" inside "for" loop takes place once.

for (i = 0; < 11; i++ ) {     k = convert.toint32(console.read());     if (k==1)     {         ans++;     }     //   console.writeline("i == {0}", i); } 

is normal in c# or doing wrong? tried search problem cannot find answers!

do

console.readline()  

instead of

console.read() 

when reach first console.read() inputstream saved first character returned read method. subsequent calls read method retrieve input 1 character @ time inputstream.

ex: first iteration:

k = console.read(); //you input "abc1", k = 

second iteration:

k = console.read(); // k = b  

and on. when last character in inputstream returned, next call console.read() display console again can input new string , hit enter.

console.read() docu


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -