Reading Input Java Code

By | October 19, 2014

We identified various patterns of reading the input which you may encounter while solving a problem on online judge.
So whenever you have to read input don’t waste your effort and time writing it again we know you know it , just copy it from here and focus more on the algorithm.We will keep adding to this list whenever we will encounter something new.

  1. Integer T(number of testcases) followed by T integers

    If you want you want to save some memory you can directly read the input and pass it to your function instead of storing it in an array

  2. Integer T(number of testcases) followed by T String

    If you want you want to save some memory you can directly read the input and pass it to your function instead of storing it in an array

  3. Initialize an array with a specific value.
    While in java all the arrays are automatically initialised to their default values.For example an int[] array is initialized to 0 , char[] to null character. So for default values you have to do nothing . But if you want all elements to be inialised to a specific value then use this function.

Leave a Reply

Your email address will not be published. Required fields are marked *