how to bufferedreader java code example
Example 1: bufferedreader in java
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
int [] arr = new int [n];
for(int i=0; i<n; i++)
{
arr[i] = Integer.parseInt(input[i]);
}
}
}
Example 2: java bufferedreader
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer st;
static String next() throws IOException {
while (st==null||!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static String readLine() throws IOException {
return br.readLine().trim();
}