Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners i am unable to identify the error in my code

Have Programming Question? Ask it here!
 
 
 


nagavellisony
i am unable to identify the error in my code
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter a character"); char ch=(char)br.read(); System.out.println("the entered character is:"+ch); }

}


Advertisement
View Answers

May 30, 2012 at 12:41 PM


Your code needs to import java.io.* package. Moreover, it also requires try catch block as it may throw exception. Anyways, we have modified your code. Here its is:

import java.io.*;

class Program { 
    public static void main(String[] args) {
        try{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        System.out.println("enter a character");
        char ch=(char)br.read();
        System.out.println("the entered character is:"+ch);
        }
        catch(Exception e){}
        }

}


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com