+ 2
Given code shows me an error in line no.13 , need help.
import java.lang.*; import java.io.*; public class ASCII { public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in())); System.out.println("Enter any character or number"); String ch = reader.readLine(); System.out.println("You have entered :-" + ch); System.out println("ASCII Value :-"+(char) ch);//Line no.:- 13 } catch (Exception e) { System.out.println("Error"); } } } //program gives ascii value
2 odpowiedzi
+ 6
In Java, you can't cast String to character. You may use charAt(int index) here. In the case of your code, replace (char)ch with ch.charAt(0).
+ 2
thanks orb