Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

The value of char's

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the exam will I need to know what the value of char primitives? I have seen on a few mock exams questions that ask what will be printed when add characters to intergers. Here's my example.

Output is
1 + 1 = 50
Now I know tricks to remeber Unicode and Hex but not Ascii values.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last time I looked at the exam objectives, nothing was said about memorizing ascii values. As far as I know, it isn't required.
Does anyone believe otherwise?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert, if u know the trick to remember Unicode ,could u pls explation
thanks
bani
 
Robert Oliver
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reassurance, Dan. It was actually your Topic test question 5 on Flow control that asked what 'd' - 'a' was that prompted me to ask the question. Obviously you don't have to know what the ascii value of 'd' or 'a' just that they are sequential and 'd' is three more than 'a'. I have not seen anything either in the objects.
Bani, Sorry to mislead you. I don't have any secret for Unicode. I only meant the relationship of Unicode, Hex to using the same codes 0-F.
For example here is a change to my code one line add's a hex value and one line adds a unicode.

Output is
0x1f + 1 = 32
\u001f + 1 = 32
[ July 30, 2002: Message edited by: Robert Oliver ]
[ July 30, 2002: Message edited by: Robert Oliver ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knowing the general concept behind Unicode characters is all you should need to know. You won't have to know the specific code for a given character. However, it would be useful if you understood things like this:

Will capitalize a given letter, if it is a lowercase letter. Notice, at no point do you need to know the value of a specific character to realize that this will output 'G' - you only need to know the nature of organization of Unicode characters.
I think that would be the most useful thing to know. Don't worry about what hex values correspond to what characters. You can look that up on the web.
I hope that helps,
Corey
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how the output is 'G'.
Can you explain?
Thanks.
Deepa
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Corey:
Can we replace ('a'-'A') with 32? Is it not
constant value on all plateform?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepa,


char c = 'g';
if ( c >= 'a' && c <= 'z' )
c = (char)(c - ('a' -'A'));
System.out.println(c);


The if statement just checks if c is a lowercase character (since a-z is sequential in Unicode/ASCII.) The key here is that a lowercase 'a' has a higher Unicode value than an uppercase 'A'. Since the uppercase characters are also sequential, the difference between 'a' and 'A' is the same for all characters. The end result would be that c would be conveted from lower to uppercase.
Hope this helps,
Paul
 
Deepa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!
Thanks for the explanation Paul.
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But for the original code:

You have to know that integral value of '1' is
49. So do we have to memories these values for 1.4 exam....?
[ August 26, 2002: Message edited by: Barkat Mardhani ]
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic