java字符转换

来源:百度知道 编辑:UC知道 时间:2024/06/14 04:17:54
编程将从键盘输入的文本中的所有大写英文字母改写为小写英文字母,小写字母改为大写字母。并统计大小字母的个数。

java字符串大小写转换的两种方法

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 text = input.readLine();
String s = convertString(text);
System.out.println(s);
}
//第一种方法
public static String convertString(String src)
{
char[] array = src.toCharArray();
int temp = 0;
for (int i = 0; i < array.length; i++)
{
temp = (int) array[i];
if (temp <= 90 && temp >= 65)
{ // array[i]为大写字母
array[i] = (char) (te