Untitled
unknown
plain_text
2 years ago
1.3 kB
3
Indexable
Never
/* Goal: Trying to use Scanner followed by BufferedReader to read keyboard inputs. Problem: Scanner worked, but BufferedReader didn't work if BufferedReader was following Scanner. Expected result is a string. But actual result is null. */ import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.FileReader; public class MyClass { public static void main(String[] args) throws IOException{ Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); // int c = scan.nextInt(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String strLine = in.readLine(); System.out.println(a); System.out.println(b); // System.out.println(c); System.out.println(strLine); } } /* INPUT & OUTPUT The Stdin Inputs are: (only typing the integer & following a breakline) 1 2 3 Expected outputs are: 1 2 3 with online java compiler outputs are: (from https://www.jdoodle.com/online-java-compiler/ And JDK version is 1.8.0_66) 1 2 null with local java compiler outputs are: (javac version is 1.8.0_281) 1 2 3 */