package day10.abs;
import java.util.Scanner;
public class reverseNew {
public static void main(String[] args) {
Scanner sc1 = new Scanner(System.in);
System.out.println(reverse1("abcdef"));
System.out.println(reverse2("123456"));
Scanner sc2 = new Scanner(System.in);
int num2 = sc2.nextInt();
System.out.println(reverse2(String.valueOf(num2)));
Scanner sc3 = new Scanner(System.in);
int num3 = sc3.nextInt();
System.out.println(reverse3(String.valueOf(num3)));
if (reverse3(String.valueOf(num3)) < 9999999) {
System.out.println("success");
}
}
public static String reverse1(String str) {
return new StringBuffer(str).reverse().toString();
}
public static String reverse2(String str) {
if (str != null || str != "") {
if (str.length() == 1) {
return str;
}
String reverseStr = "";
for (int i = str.length() - 1; i < str.length() && i >= 0; i--) {
reverseStr = reverseStr + str.charAt(i);
}
return reverseStr;
}
return str;
}
public static int reverse3(String str) {
if (str != null || str != "") {
if (str.length() == 1) {
return Integer.parseInt(str);
}
String reverseStr = "";
for (int i = str.length() - 1; i < str.length() && i >= 0; i--) {
reverseStr = reverseStr + str.charAt(i);
}
return Integer.parseInt(reverseStr);
}
return Integer.parseInt(str);
}
}
字符串翻转String int类型
猜你喜欢
转载自blog.csdn.net/weixin_42498050/article/details/105211307
今日推荐
周排行