- 2

How to input a character in Java using BufferedReader and Scanner class ?

21st Jan 2018, 2:33 AM
Jitendra Singh
Jitendra Singh - avatar
9 Answers
+ 3
Scanner sc = new Scanner ( System .in); char c = sc.next().charAt( 0 );
21st Jan 2018, 3:08 AM
šŸ¦‹FEATHERšŸ¦‹
šŸ¦‹FEATHERšŸ¦‹ - avatar
+ 1
public class Wrap { public static void main( String [] args) { BufferedReader br = new BufferedReader(new InputStreamReader (System.in)); char c = ( char )br.read(); //Here you go System .out.println(c); } }
21st Jan 2018, 3:02 AM
šŸ¦‹FEATHERšŸ¦‹
šŸ¦‹FEATHERšŸ¦‹ - avatar
+ 1
Ethan... How to input character using Scanner class
21st Jan 2018, 3:05 AM
Jitendra Singh
Jitendra Singh - avatar
0
once again thank you
21st Jan 2018, 3:19 AM
Jitendra Singh
Jitendra Singh - avatar
0
you should also use throws IOException
22nd Jul 2018, 4:42 PM
Nethra
0
What is the mistake in the below code?Please let me know.. import java.io.*; public class Buffersol { public static void main(String args[]) throws IOException { int a; System.out.println("ENTER THE VALUE OF a"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); a=Integer.parseInt(br.read()); System.out.println("value of a is" +a); } }
22nd Jul 2018, 4:44 PM
Nethra
0
a=Integer.parseInt(br.read()); this is wrong. use readLine() not read()
16th Mar 2019, 4:59 PM
Shyama Nair
Shyama Nair - avatar
0
br.readline().charAt(0); this is much useful while ,(char)input.read();throws some error if u put it in loop , to avoid that i would suggest the use of br.readline().charAt(0);
3rd Aug 2019, 6:58 AM
Monick Verma
Monick Verma - avatar
- 1
Thanks a lot
21st Jan 2018, 3:03 AM
Jitendra Singh
Jitendra Singh - avatar