473,320 Members | 2,147 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,320 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 2324
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.