- 2
How to input a character in Java using BufferedReader and Scanner class ?
9 Antworten
+ 3
Scanner sc = new Scanner ( System .in);
char c = sc.next().charAt( 0 );
+ 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);
}
}
+ 1
Ethan...
How to input character using Scanner class
0
once again thank you
0
you should also use throws IOException
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);
}
}
0
a=Integer.parseInt(br.read());
this is wrong.
use readLine() not read()
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);
- 1
Thanks a lot