[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

[Java] toUpperCase OK med String men ikke med char



Hej NG
Er ved at lære programering med Java som udgangspunkt og er tæmmelig indlysende ikke helt klar i spyttet -endnu :)


Følgende kode fungerer fint hvis man lige ser bort fra den fejlagtige håndtering af UTF-8


public class myToUpperCase // Class header
{ // Class body begin
public static String myToUpperCase(String s) // Wrap of String method toUpperCase
{
return s.toUpperCase(); // Return input string as all upper case string
}
// Test the code
public static void main(String[] argv)
{
System.out.println(myToUpperCase("aBRAKADABRA SiM sAlA Bim - Ælle BæLLE Mig Fortælle")); // Test with string containing both upper and lower case characters
}// End: Test
// Output is: ABRAKADABRA SIM SALA BIM - ÃLLE BæLLE MIG FORTæLLE
// Check: Semi-OK. Return only upper case as specified, but faulty handling of Locale characters.

}// End: class



Men laver jeg varianten af samme kode hvor der behandles char istedet går det helt i hårknude :'(



import java.lang.Character.*;
public class myToUpperCase // Class header
{ // Class body begin
public static char myToUpperCase(char c) // Wrap of Character method toUpperCase
{
return Character.toUpperCase(c); // Return input character as upper case
}
// Test the code
public static void main(String[] argv)
{
System.out.println(myToUpperCase(a)); // Test with lower case character
}// End: Test
// Output is: Error
// Check: Failed.


}// End: class

I det specifikke tilfælde brokker compileren sig over at a ikke er en kendt variabel og hvis jeg putter " om; altså: "a", opfattes den som en et-tegns streng og så klages der (forståeligt nok) over type mismatch.

Jeg tror slet ikke jeg har fattet char metoderne...?

På forhånd tak.

--
Med venlig hilsen
/Zmit/
RLU # 314205


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-11-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *