用java写一个将小写字母转化成大写字母代码
时间: 2023-12-03 09:44:36 浏览: 49
可以使用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`。
相关问题
用Java写一个讲小写字母转换成大写字母以#结尾的代码,
Java中可以使用String类的toUpperCase()方法将小写字母转换成大写字母。例如:
String str = "hello";
String upperStr = str.toUpperCase();
System.out.println(upperStr);
输出结果为:
HELLO
用java将用户输入的大写字母转换成小写字母。
请看下面的 Java 代码:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个大写字母:");
String input = scanner.nextLine();
char c = input.charAt(0);
if (c >= 'A' && c <= 'Z') {
c = (char) (c + 32);
System.out.println("转换后的小写字母为:" + c);
} else {
System.out.println("输入的不是大写字母!");
}
}
}
```
这个程序会提示用户输入一个大写字母,然后将其转换成小写字母输出。如果用户输入的不是大写字母,则会输出错误提示信息。