473,419 Members | 1,647 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,419 software developers and data experts.

Why doesn't character datatype take up more than one character ?

Hello.
I use BlueJ 3.0.1
I am writing a program to dictionarize words(arrange words in dictionary order).

But the 'char' type isn't working properly.

Expand|Select|Wrap|Line Numbers
  1. char ch1 = 'qwerty' ;//shows error
  2. char ch2 = 'qwedrt';
  3. if(ch1>ch2)
  4. {
  5. System.out.println(ch2);
  6. System.out.println(ch1);
  7. }
  8. else
  9. {
  10. System.out.println(ch1);
  11. System.out.println(ch2);
  12.  
Please help with it and program.
* NOTE for Bytes.com : THIS IS NOT A HOMEWORK QUESTION.
Sep 15 '10 #1

✓ answered by Dheeraj Joshi

Use
Expand|Select|Wrap|Line Numbers
  1. java.util.Arrays.sort(MyStringArray);
  2.  
Otherwise put the strings in sortedset. And retrieve them

Regards
Dheeraj Joshi

14 2330
given code is a snippet
Sep 15 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. 'qwerty' 
  2.  
This is certainly not a character. You can have a single character within single quote for char data type.

Expand|Select|Wrap|Line Numbers
  1. char ch2 = 'p'; 
  2.  
Regards
Dheeraj Joshi
Sep 16 '10 #3
bt then hw will i dictionarize ?
Sep 18 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
What do you mean by dictionarize? I am unable to understand your question.

Regards
Dheeraj Joshi
Sep 19 '10 #5
Aim of my program is to arrange entered words in dictionary order....hw would i do that !!
Sep 19 '10 #6
Dheeraj Joshi
1,123 Expert 1GB
Take String datatype to handle this.

Regards
Dheeraj Joshi
Sep 20 '10 #7
But > , < , = operators don't work with string !
Sep 20 '10 #8
Dheeraj Joshi
1,123 Expert 1GB
Use
Expand|Select|Wrap|Line Numbers
  1. java.util.Arrays.sort(MyStringArray);
  2.  
Otherwise put the strings in sortedset. And retrieve them

Regards
Dheeraj Joshi
Sep 20 '10 #9
kk. you knw by any method i can convert string to char ???
like i entered + as string datatype but want to convert it to + of char datatype
Sep 20 '10 #10
Dheeraj Joshi
1,123 Expert 1GB
You can convert it into character array.

Expand|Select|Wrap|Line Numbers
  1. char[] characters = str.toCharArray();
  2.  
Take the char at position 0

or

Expand|Select|Wrap|Line Numbers
  1. char myChar = str.charAt(0);
  2.  
Regards
Dheeraj Joshi
Sep 20 '10 #11
without arrays?
Sep 21 '10 #12
Dheeraj Joshi
1,123 Expert 1GB
See second option in my last post(11).

Regards
Dheeraj Joshi
Sep 21 '10 #13
it workd ...thnx
Sep 27 '10 #14
Dheeraj Joshi
1,123 Expert 1GB
Good to know that.
Sep 28 '10 #15

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

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
5
by: Gary Mayor | last post by:
Hi, If I have the ' character within the javascript:pick command it doesn't work. Is there some sort of way of escaping these characters like in server side languages. function pick(symbol) {...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
9
by: Erik Leunissen | last post by:
L.S. I've observed unexpected behaviour regarding the usage of the '#' flag in the conversion specification in the printf() family of functions. Did I detect a bug, or is there something wrong...
14
by: gooooglegroups | last post by:
I want to transform the following xml file ------------------------------------------------------------------------ <?xml version="1.0" encoding="ISO-8859-1"?> <a> <b attrib="if 3 2"> </b> ...
44
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall...
6
by: Paddy3118 | last post by:
Hi, I am trying to find out if thhe following snippet would be valid XML - specifically the use of '>' between the tags: <expressionA>=B </expression> Should it be: <expressionA&gt;=B...
2
by: George2 | last post by:
Hello everyone, I need to know the wide character (unicode) and multibyte (UTF-8) values of a character string of czech. I personally know nothing about czech. Is the following approach...
13
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i have come across a situation in my project where i read a text file with some characters greater than hex 0x7f. i need to write character (0xE0) to a new file as an exception. however when i...
2
by: Mirco Wahab | last post by:
After reading through some (open) Intel (CPU detection) C++ source (www.intel.com/cd/ids/developer/asmo-na/eng/276611.htm) I stumbled upon a sketchy use of multibyte characters - - - - - - - - -...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.