用Java MyEdipse编写一个程序,将一个小写字母转换成相应的大写字母并显示输出,怎么做?
1个回答
展开全部
单纯的一个字母转换那很容易的,而且常理来讲要转换的字符来源于键盘,所以要从键盘上获取字符,然后进行字符转换再输出。给你一个大小写转换的程序吧! import java.io.*;public class convertToPrintString
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Please enter your word:");
String t = input.readLine();
String s = convertString(t);
System.out.println(s);
}
public static String convertString(String str)
{
String upStr = str.toUpperCase();
String lowStr = str.toLowerCase();
StringBuffer buf = new StringBuffer(str.length());
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==upStr.charAt(i))
{
buf.append(lowStr.charAt(i));
}
else
{
buf.append(upStr.charAt(i));
}
}
return buf.toString();
}
}
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Please enter your word:");
String t = input.readLine();
String s = convertString(t);
System.out.println(s);
}
public static String convertString(String str)
{
String upStr = str.toUpperCase();
String lowStr = str.toLowerCase();
StringBuffer buf = new StringBuffer(str.length());
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==upStr.charAt(i))
{
buf.append(lowStr.charAt(i));
}
else
{
buf.append(upStr.charAt(i));
}
}
return buf.toString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询