برامج

iam having a problem with this java assignment [الأرشيف] - برامج نت

المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : iam having a problem with this java assignment


thebrood_guy8
06-13-2009, 05:07 PM
write a method that converts an uppercase letter to a lowercase letter. use the following method header
public static char
upperCaseToLowerCase(char ch)
for example, uppercasetolowerCase('B') returns b

in Ascii uppercase letters appear before lower case letters. the offset between any upper case letter and its corresponding lowercase letter
is the , so you can find a lowercase ltter from its corresponding uppercase letter as follows:
int offset = (int)'a' -(int)'A';
char lowercase=(char)(int)uppercase+offset);




this is what i wrote .iam messed up i need help :

import java.util.Scanner;
public class uppertolower

{
public static uppertolower main(String[] args)
{
Scanner input= new Scanner(System.in);


char ch= input.nextchar();
int offset = (int)'a' -(int)'A';

System.out.println("this is the Result" +ch);
return ch;
}

}

mohamed17
06-16-2009, 07:11 PM
import java.util.*;
public class uppertolower {


public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
System.out.println("Entrer Votre Caracter :");
String ch=input.nextLine();
char car=upperCaseToLowerCase(ch.charAt(0));

System.out.println("this is the Result " +car);

}
public static char upperCaseToLowerCase(char car)
{
int c;
c=(int)car-(int)'A';
if(c<0 || c>26)
{
System.out.println("Caracter non Valide!!!");
System.exit(0);
}
return (char) ('a'+c);
}