1.不用函数。
2.好像是+65啊什么的,忘记了。
3.例如:输入a====>输出A
       输入A====>输出a4.有没有高手知道怎么做?急!

解决方案 »

  1.   


    public static char reverse(char c) {
    if(c >= 'a'&& c <= 'z') {
    return (char)(c - 32);
    } else{
    return (char)(c + 32);
    }
    }
      

  2.   

                    int old = 'a';//为你输入的字符
    if(old>=97 && old<=122)//小写
    {
    old = old-32;
    }else if(old>=65 && old<=90){//大写
    old = old+32;
    }
    System.out.println((char)old);
      

  3.   

    下面这个小程序只运行一次,对其他一些例外我没处理,还有一些异常我直接抛出了。
    基本上能达到目的,如果想让它变了健壮点,怎么运行都死不了,那你自己改,因为有点耗时间 呵呵...import java.io.*;
    public class S {
    public static void main(String[] args) throws Exception {
    BufferedReader i = new BufferedReader(new InputStreamReader(System.in));
    int temp = i.read();
    char c = (char)temp;
    if(temp>=65 && temp<=96)
    temp += 32;
    else
    temp -= 32;
    System.out.println((char)temp);
    }
    }
      

  4.   

    String的方法.方法名是toLowerCase()和toUpperCase()
    平时可以多看看API文档.熟悉一下里面的方法
      

  5.   


    import javax.swing.*;
    public class ConvertChar
    {
        public static void main(String[] args) throws Exception 
        {
         char[] s1;
         String s,s2 ="";
         char c;
         s=JOptionPane.showInputDialog(null,"请输入英文字母:","英文字母大小写自动转换 ",JOptionPane.INFORMATION_MESSAGE);
         s1=s.toCharArray();
         int n=s1.length;
         try
         {
             for(int j=0;j<n;j++)
             {   
                 c=s1[j];
                 if(c<65||c>90&&c<97||c>122)//当输入非字母时跳出
                 {
             throw new Exception("Sorry,请输入字母!");
                    }
                 else if(c>=97 && c <=122)//小写 转大写
                 { 
                 s1[j]=(char)(c-32); 
                 }
                 else if(c>=65 && c <=90){//大写 转小写
             s1[j]=(char)(c+32);
                 } 
             }
            for(int j=0;j<n;j++)//输出转换后的字母
            { 
              s2=s2+s1[j];
            }
            JOptionPane.showMessageDialog(null,"你输入的字母为:"+s+"\n字母大小写转换后:"+s2,"英文字母大小写自动转换 ",JOptionPane.INFORMATION_MESSAGE);
         }
         catch(Exception e)
         {
             JOptionPane.showMessageDialog(null,e.getMessage(),"Sorry,你输入了非字母字符!",JOptionPane.ERROR_MESSAGE);
         }
         finally
         {
             System.exit(0);
         }    } }你可以输入一个字母字符串,若字母是大写自动转换成小写,是小写就转大写!
    若输入:SDFdf
    就输出:sdfDF
      

  6.   

    toLowerCase() 
              使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
    toUpperCase() 
              使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
      

  7.   

    up 用toLowerCase()跟toUpperCase()更好啦!!!
      

  8.   

    String 类里直接有方法
    一般教科书里都会有提到
      

  9.   

    谢谢各位的支持,有了这个例子,我也就想起来,我的思路了。
    package chap1;public class ex {
    public static void main(String[] args){
    int old='a';
    old-=32;
    System.out.println((char)old);



    }
    }