BufferedReader can be used to input integers, floats and so on
import java.io.*;
public class Wrap {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int h = Integer.parseInt(br.readLine());
}
}
Is there any way to enter characters using it?
use the read method
private static void handleCharacters(Reader reader)
throws IOException {
int r;
while ((r = reader.read()) != -1) {
char ch = (char) r;
//process
}
}
Here is how you can accumulate the chars in an array of size 100.
char charArray[] = new char[ 100 ];
int i = 0;
BufferedReader buffer = new BufferedReader(
new InputStreamReader(System.in));
int c = 0;
while((c = buffer.read()) != -1 && i < 100) {
char character = (char) c;
charArray[i++] = c;
}
System.out.println(charArray);
Try with this code
public class Wrap {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char c = (char)br.read();
System.out.println(c);
}
}
char a=br.readLine().charAt(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.