JAVA Tutorial II – Data Types (Part V – Char)
What is a Char?
Char is short for character, and they are interesting data types.They can only hold single values, which isn’t very useful if you are trying to hold a lot of data. But they do have their uses. If you want to create a multiple choice test, you can use chars as the values, but you are going to have to convert them from Strings. That is a complicated process which I am not inclined to explain in this tutorial. What I will explain is how to declare the value of a char.
Here is the Code:
So we’ll declare a simple char, and output it.
import java.util.Scanner;public class Char {public static void main(String[] args) {</p>
Scanner charscanner = new Scanner(System.in);
char x = ‘a’;
System.out.print(“The character is ” + x);
}
}</td> </tr> </tbody> </table> This is pretty self-explanatory. But the only difference, is in order to declare a char, you need to use only a single character like a period or the letter “a.” So this is how you use a Char in Java |
Leave a Comment