java英文大小写转换
时间: 2024-06-01 22:06:44 浏览: 16
Java中的大小写转换可以通过String类中的toLowerCase()和toUpperCase()方法实现。toLowerCase()方法将字符串转换为小写形式,而toUpperCase()方法将字符串转换为大写形式。
例如,将一个字符串str转换为大写形式可以使用以下代码:
```
String str = "Hello World";
String upperStr = str.toUpperCase();
System.out.println(upperStr);
```
输出结果为:
```
HELLO WORLD
```
同样地,将一个字符串str转换为小写形式可以使用以下代码:
```
String str = "Hello World";
String lowerStr = str.toLowerCase();
System.out.println(lowerStr);
```
输出结果为:
```
hello world
```
相关问题
Java的大小写转换
Java中大小写转换可以使用String类的toUpperCase()和toLowerCase()方法。例如:
```java
String str = "Hello World";
String upperStr = str.toUpperCase(); // 转换为大写
String lowerStr = str.toLowerCase(); // 转换为小写
```
java人民币大小写转换
以下是一个Java程序,用于将人民币小写金额转换为大写金额:
```java
import java.text.NumberFormat;
public class RMBConverter {
public static void main(String[] args) {
double num = 20100104600.01;
String s = upperCase2(num);
System.out.println("大写金额:" + s);
}
public static String upperCase2(double num) {
String[] fraction = {"角", "分"};
String[] digit = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
String[][] unit = {{"元", "万", "亿"}, {"", "拾", "佰", "仟"}};
String head = num < 0 ? "负" : "";
num = Math.abs(num);
String s = "";
for (int i = 0; i < fraction.length; i++) {
s += (digit[(int) (Math.floor(num * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
}
if (s.length() < 1) {
s = "整";
}
int integerPart = (int) Math.floor(num);
for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
String p = "";
for (int j = 0; j < unit[1].length && num > 0; j++) {
p = digit[integerPart % 10] + unit[1][j] + p;
integerPart /= 10;
}
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
}
return head + s.replaceAll("(零.)*零元", "元").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
}
}
```
运行以上代码,将会输出人民币小写金额20100104600.01的大写金额为贰佰零壹亿零壹佰万肆仟陆佰元零壹分。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)