import java.util.Scanner
/**
* @Author: Cool_Wu
* @Date: 2020-11-02 21:26
*
public class Test {
public static void main(String[] args) {
getInteger()
getReverseInteger()
}
private static void getInteger() {
Scanner scanner = new Scanner(System.in)
System.out.println("请输入一个整数:")
int num = scanner.nextInt()
System.out.println(num)
}
private static void getReverseInteger() {
Scanner scanner = new Scanner(System.in)
System.out.println("请输入一个整数:")
String num = scanner.next()
char[] chars = num.toCharArray()
int[] nums = new int[chars.length]
for (int i = 0i <chars.lengthi++) {
nums[chars.length-1-i] = Integer.parseInt(String.valueOf(chars[i]))
}
for (int result : nums) {
System.out.print(result)
}
}
}
运行结果
你想要什么程序呢?我给你一个示例,将一个字符串里面的大写字母转成小写字母,或者将一个字符串的小写字母转成大写字母:import java.util.Scanner
public class ToUpAndLow {
private static void ToUper(String str){
char strInput = 0
int num = 0
String outPutStr = ""
for (int i = 0i <str.length()i++) {
strInput = str.substring(i,i + 1).charAt(0)
if(strInput >= 97 &&strInput <= 122){
num = strInput - 32
outPutStr += String.valueOf((char)num)
} else {
outPutStr += String.valueOf((char)strInput)
}
}
System.out.println("该字符串的大写形式是:" + outPutStr)
}
private static void ToLower(String str){
char strInput = 0
int num = 0
String outPutStr = ""
for (int i = 0i <str.length()i++) {
strInput = str.substring(i,i + 1).charAt(0)
if(strInput >= 65 &&strInput <= 90){
num = strInput + 32
outPutStr += String.valueOf((char)num)
} else {
outPutStr += String.valueOf((char)strInput)
}
}
System.out.println("该字符串的小写形式是:" + outPutStr)
}
public static void main(String[] args) {
System.out.print("请输入要转换的字符串:")
String inputStr = new Scanner(System.in).next()
ToUper(inputStr)
ToLower(inputStr)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)