用Java写一个讲小写字母转换成大写字母以#结尾的代码,
时间: 2023-05-16 07:07:02 浏览: 77
Java中可以使用String类的toUpperCase()方法将小写字母转换成大写字母。例如:
String str = "hello";
String upperStr = str.toUpperCase();
System.out.println(upperStr);
输出结果为:
HELLO
相关问题
用java写一个将小写字母转化成大写字母代码
可以使用Java内置的方法toUpperCase()将小写字母转换成大写字母。具体实现代码如下:
```java
public class LowerToUpper {
public static void main(String[] args) {
String input = "hello world";
String output = input.toUpperCase();
System.out.println(output);
}
}
```
在这个例子中,我们将输入字符串`"hello world"`中的小写字母转换成大写字母,并将结果输出到控制台中。运行这个程序,你会看到输出结果为`HELLO WORLD`。
用C写一个将小写字母转换成大写字母
以下是将小写字母转换成大写字母的C代码:
#include <stdio.h>
int main() {
char c;
printf("请输入一个小写字母:");
scanf("%c", &c);
if (c >= 'a' && c <= 'z') {
c = c - 32;
printf("转换后的大写字母为:%c\n", c);
} else {
printf("输入的不是小写字母!\n");
}
return 0;
}