473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Java char data type problem

Can anyone please tell me why i am getting an error in the following code?

Expand|Select|Wrap|Line Numbers
  1. class Char_Demo
  2. {
  3.     public static void main(String[] n)
  4.     {
  5. // we all know we can store a character literal like A or //B in an char variable
  6.  
  7. char c='A';
  8. System.out.println("Character c has" +c);   //output is A
  9.  
  10.     // we can even store the ASCII value for A
  11.  
  12. char c1=65;
  13. System.out.println("Character c1 has" +c1 );//output is A
  14.  
  15.  
  16.     //But now i want to store a number as a character        
  17.  
  18.     char c2='5';    // 5 stored as a character    System.out.println("Character c2 has" +c2 );//output is 5
  19.  
  20. // but when i store a number which has more then 1 digit //i get an compile-time error
  21.  
  22. char c3='12';        // error....why this error comes
  23. System.out.println("Character c3 has" +c3 );
  24.     }
  25. }
  26.  
]
Jul 28 '11 #1
2 3326
There is an error because in Java we have char datatype containing only one char. If you want to store more than one char, you have to use String class.
Jul 28 '11 #2
Thanks for the reply........I now have understood my mistake....................Thanks
Jul 28 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Derk | last post by:
I have an VB App that reads an Excel Sspreadsheet and it seems to having problems determining the data type of a column. The column in question has alpha numeric content eg S001, B123 or 1234. I am...
1
by: Lukelrc | last post by:
Hi all. I'm having trouble connecting to my sql server database correctly beacause of value type problems, specifically the date fields. When i try and run the page i get the follwoing error: ...
3
by: kieran | last post by:
Hi, I have a form which is submitting into a sql server db. i have one of the fields set to ntext which says length of 16. when i insert info, it only sumbits about a paragraph and when i pull...
1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
0
by: Olav | last post by:
I'm trying to use Python / COM to do some drawing automation. Here is a simple code example: This code uses a object made by the Opendwg-org. Autocad has a similar object with the same methods...
2
by: Savas Ates | last post by:
I have a field in my table which has currency values like this 41.2 10 24.12 in my vb.net application i have a variable which i assigned as decimal Dim mymoney as Decimal mymoney...
0
by: selacika | last post by:
Hi all; My question is about how to get non-font information part of a field of text data type using an sql sentence. Shortly how to get pure info from a text data type field. Example: Value of...
2
by: rohit deshpande | last post by:
Hi, i am learning VC++, i am inputting some text from edit box of dialog box to a CString variable. now i want to convert it to char data type. i don't know how.....????? plzz help
1
by: sangig | last post by:
hi forum, can any body help me out with the Java equivalent data type for MSSQL IMAGE data type? Thanks Sangig
2
by: SDStoic | last post by:
Hi there... I have an Oracle 9.2 table with several columns having an "NCLOB" data type. I cannot change the data type on the database. When attempting to query this linked table without...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.