Wrox Programmer Forums
|
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2010, 12:37 AM
Registered User
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default java and unicode confusion

trying out an example in this book (apologize for all the nested ifs):
Code:
public class LetterCheck {
 public static void main (String args[]){
  char symbol='A';
  symbol= (char)(128.0*Math.random());

  if (symbol>='A')
   {if (symbol<='Z')
     {System.out.println("Char is a capital letter: "+symbol+" - "+(double)(symbol));}
    else
     {if (symbol>='a')
       {if (symbol<='z') 
         {System.out.println("char is a lowercase letter: "+symbol+" - "+(double)(symbol));}
        else 
         {System.out.println("Char is greater than a but not a letter: "+symbol+" - "+(double)(symbol));}
       }
      else
       {System.out.println("Char is between Z and a: "+symbol+" - "+(double)(symbol));}
     }
   }
  else {System.out.println("Char is less than A: "+symbol+" - "+(double)(symbol));}}}
the console output is writting non-printable characters like 21 (NAK) in some symbol that i cant find on any ASCII table. im just wondering what agent specifically is responsible for this.

also, when i save my source code in wordpad with a filetype of unicode text document it doesnt compile. if java supports unicode why is this even happing?

i really want to understand completely the issues here, so if you know of any links that would enlighten me with a full explanation i would greatly appreciate it. im sure this has been asked before, i just cant find the answer.

thanks so much!
 
Old October 25th, 2010, 12:04 PM
Registered User
 
Join Date: Oct 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The last bits
Code:
else 
         {System.out.println("Char is greater than a but not a letter: "+symbol+" - "+(double)(symbol));}
       }
      else
       {System.out.println("Char is between Z and a: "+symbol+" - "+(double)(symbol));}
     }
   }
  else {System.out.println("Char is less than A: "+symbol+" - "+(double)(symbol));}}}
You should not print the symbol as it will probably contain a control character which will mess you display up
Remove all the "+symbol+" bits
You also seem to have a misunderstanding about casting (double)(symbol) bits
println & indeed anything expecting a String type will perform a toString() if it can
Also casting is between numeric types only, it has nothing to do with String!

Do not use Wordpad, either use notepad or try some other simple text editor, wordpad is a mini wordprocessor (I use Notepad++ from sourceforge)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusion with terminology... vb89 XML 5 May 7th, 2010 06:36 AM
Errata confusion morganstein BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 0 October 10th, 2008 05:11 PM
Class' Confusion dpkbahuguna Beginning VB 6 4 September 20th, 2006 11:16 PM
Some confusion in these code hpatel_it ASP.NET 1.0 and 1.1 Basics 0 August 30th, 2006 08:19 AM
.net Confusion reyboy General .NET 1 December 29th, 2004 08:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.