「java怎么将字母转大写」java怎么大小写字母转换
今天给各位分享java怎么将字母转大写的知识,其中也会对java怎么大小写字母转换进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
用JAVA语言编写字母大小写转换
用字符串的
toUpperCase()
小写转为大写
或
toLowerCase()方法
大写转为小写
如:
(小转为大)
String
str
=
"abcd";
str.toUpperCase();
str
就等于"ABCD"了
如何用java语言把小写换成大写
toLowerCase(); //字符串转成小写
toUpperCase(); //字符串转成大写
String str = "abcABC";
String a = str.toLowerCase();
String b = str.toUpperCase();
System.out.println("a:"+a +"b:"+b);
输出结果a:abcabc b:ABCABC
java中如何进行大小写字母转换?
1.创建工程,或使用已有工程,在工程下创建包,包内新建一个类,我命名为Cases类,大家根据自己喜好随便命名,但请保持类名与文件名一致。
2.先确定单个字符,小写字母a与大写字母A之间的数值大小System.out.println((int)('z')-(int)('Z'));样一个语句就搞定了 。
3.思路是,字符串变字符数组,大转小,字符值加32,小转大,字符值减32 。大写字母范围是:65-90,小写字母范围是:97-122。
4.同理,大转小这么写:char[] queue = str.toCharArray();for (int index = 0; index queue.length; index++) {if (((int) queue[index] 64) ((int) queue[index] 91)) {queue[index] = (char) ((int) queue[index] + 32);}System.out.println("Lower: " + String.valueOf(queue));
5.写一个测试主函数看看结果:System.out.println("originalstring:"+ORIGINAL_STRING);printLowerCase(ORIGINAL_STRING);printUpperCase(ORIGINAL_STRING);即可。
java编写一个字母大小写转换器?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CaseConverter extends JFrame {
private JTextField inputField;
private JTextField outputField;
private JButton capitalButton;
private JButton lowercaseButton;
public CaseConverter() {
// 设置窗口标题
setTitle("Case Converter");
// 设置窗口布局为FlowLayout
setLayout(new FlowLayout());
// 创建组件
inputField = new JTextField(20);
outputField = new JTextField(20);
capitalButton = new JButton("Capital");
lowercaseButton = new JButton("Lowercase");
// 将组件添加到窗口中
add(inputField);
add(outputField);
add(capitalButton);
add(lowercaseButton);
// 向按钮添加按压事件监听器
capitalButton.addActionListener(new CapitalListener());
lowercaseButton.addActionListener(new LowercaseListener());
}
// 定义Capital按钮的按压事件监听器
private class CapitalListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// 从输入文本框中获取输入字符串
String input = inputField.getText();
// 将字符串中的大写字母转换为小写字母,其它字符不变
String output = input.toLowerCase();
java怎么将字母转大写的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java怎么大小写字母转换、java怎么将字母转大写的信息别忘了在本站进行查找喔。