英文字母大小写自动转换 1.不用函数。2.好像是+65啊什么的,忘记了。3.例如:输入a====>输出A 输入A====>输出a4.有没有高手知道怎么做?急! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static char reverse(char c) { if(c >= 'a'&& c <= 'z') { return (char)(c - 32); } else{ return (char)(c + 32); } } 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); 下面这个小程序只运行一次,对其他一些例外我没处理,还有一些异常我直接抛出了。基本上能达到目的,如果想让它变了健壮点,怎么运行都死不了,那你自己改,因为有点耗时间 呵呵...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); }} String的方法.方法名是toLowerCase()和toUpperCase()平时可以多看看API文档.熟悉一下里面的方法 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 toLowerCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为小写。toUpperCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。 up 用toLowerCase()跟toUpperCase()更好啦!!! String 类里直接有方法一般教科书里都会有提到 谢谢各位的支持,有了这个例子,我也就想起来,我的思路了。package chap1;public class ex { public static void main(String[] args){ int old='a'; old-=32; System.out.println((char)old); } } 做选课系统的需求报告遇到点问题 swing图片处理? JProgressBar 进度显示问题 不知道这个是什么错误,帮忙解决下,谢啦~~ 问一个关于System.exit(0)作用的问题 请教一下 这两个程序有什么不同?? char类型的问题 国外有哪些好的程序员论坛?请各位介绍几个 我用swing编写的applet,但是ie5和ie6都不支持,显示不了。请问当客户端浏览器不支持相应版本的apple时 "手动" 安装运行环境JVM的解决办法 运行时对象的动态创建与执行? 把YYYY-MM-DD 转化为YYYYMMDD ? 请教 符号三角形 数组越界问题
public static char reverse(char c) {
if(c >= 'a'&& c <= 'z') {
return (char)(c - 32);
} else{
return (char)(c + 32);
}
}
if(old>=97 && old<=122)//小写
{
old = old-32;
}else if(old>=65 && old<=90){//大写
old = old+32;
}
System.out.println((char)old);
基本上能达到目的,如果想让它变了健壮点,怎么运行都死不了,那你自己改,因为有点耗时间 呵呵...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);
}
}
平时可以多看看API文档.熟悉一下里面的方法
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
使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
toUpperCase()
使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
一般教科书里都会有提到
package chap1;public class ex {
public static void main(String[] args){
int old='a';
old-=32;
System.out.println((char)old);
}
}