Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Problem with comparison

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

When I run the following program

public class Test {

public static void main(String[] args){

char pc ='?';

System.out.println("pc1 ="+pc);
System.out.println("pc2 ="+(char)0xfff0);
System.out.println((pc ==(char)0xfff0));

}

}

I get this result

pc1 =?
pc2 =?
false

but my understanding is, System.out.println((pc ==(char)0xfff0));

should print true but why false.

I would appreciate anyone who can help me understand this.

Thank you
raj

[ May 10, 2007: Message edited by: Raj Mellon ]
[ May 10, 2007: Message edited by: Raj Mellon ]
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the Unicode-value of '?' is 0x003f and not 0xfff0.

System.out.println("pc2 ="+(char)0xfff0); gives "pc2 = ?" just because your JVM does not know how to print the character '\ufff0' but that does not mean that the character is the same as '?'
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic