编写程序,任意输入一行字符串,将其中的小写字母变成大写字母,并输出结果。
时间: 2023-10-04 22:08:27 浏览: 67
好的,以下是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 inputStr = scanner.nextLine();
String outputStr = inputStr.toUpperCase();
System.out.println("转换后的字符串为:" + outputStr);
}
}
```
程序首先使用`Scanner`类从控制台读取一行字符串,然后使用`toUpperCase()`方法将其中的小写字母全部转换成大写字母,并将结果存储到一个新的字符串变量`outputStr`中。最后,输出转换后的字符串即可。
相关问题
编写程序,输入一个字符串,将其中的小写字母修改为大写字母 输出该字符串
您可以使用 Python 编写以下程序来将输入字符串中的小写字母修改为大写字母:
```python
string = input("请输入一个字符串:") # 获取用户输入的字符串
upper_string = string.upper() # 将字符串中的小写字母修改为大写字母
print("修改后的字符串为:", upper_string) # 输出修改后的字符串
```
这段代码中,我们首先使用 `input()` 函数获取用户输入的字符串,并将其保存在变量 `string` 中。然后,我们使用字符串的 `upper()` 方法将其中的小写字母修改为大写字母,并将结果保存在变量 `upper_string` 中。最后,我们使用 `print()` 函数输出修改后的字符串。
例如,如果用户输入了字符串 "Hello, world!", 则程序会输出 "HELLO, WORLD!"。
输入一串字符,将其中小写字母改为大写字母并输出新的字符串
好的,您可以尝试使用如下的Python代码来实现该功能:
```python
input_str = input("请输入一串字符:")
output_str = ""
for ch in input_str:
if ch.islower():
output_str += ch.upper()
else:
output_str += ch
print(output_str)
```
使用这段代码可以实现将输入字符串中的小写字母全部转换成大写字母,并输出转换后的字符串。