Search code examples
javajava.util.scannerstdinbufferedreaderinputstreamreader

Java Input from console giving unexpected values


In the given code,

Input:
1
7

Output:
1

Output should be 7. What am I missing??

import java.io.*;
import java.util.*;

class compiler 
{
    public static void main(String args[] ) throws Exception 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int testcases = Integer.parseInt(br.readLine());

        //  System.out.println("If this statement is added it works as expected!")

        int n=Integer.parseInt(br.readLine());

        System.out.println(n);
    }
}

*I also tried using scanner


Solution

  • This should work. if you are not using an IDE, then maybe you changed your code and didn't compile again. so you are essentially running an old code with different output?