1.数字反转

1.数字反转_第1张图片
题目
AC

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if(n>=0) {
			StringBuilder str = new StringBuilder();
			str.append(n);
			StringBuilder str1 = str.reverse();
			String str2 = str1.toString();
			int m = Integer.valueOf(str2);
			System.out.println(m);
		}else {
			String str = n+"";
			String str1 = str.substring(1,str.length());//去掉负号			
			StringBuilder str2 = new StringBuilder();
			str2.append(str1);
			StringBuilder str3 = str2.reverse();		
			String str4 = str3.toString();
			int k = Integer.valueOf(str4);
			k = -k;
			System.out.println(k);
		}
	}	
}

你可能感兴趣的:(蓝桥杯省赛(Java组),java,开发语言)