在一行中输入一个四位整数
(
)。
输出一个四位整数,为
反向后的结果;若高位为零,也需保留。
1234
4321
在这个样例中,输入的四位数是,反向输出后得到
。
1000
0001
在这个样例中,输入的四位数是,反向输出后得到
,注意保留了前导零。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
// 拆分四位:千位、百位、十位、个位
int qian = a / 1000;
int bai = (a / 100) % 10;
int shi = (a / 10) % 10;
int ge = a % 10;
// 反转后:个位→千位,十位→百位,百位→十位,千位→个位
int reverse = ge * 1000 + shi * 100 + bai * 10 + qian;
// 格式化输出:%04d 表示“至少4位,不足补0”; 比如输入 1000, 输出 0001,保留前面的0;
System.out.printf("%04d\n",reverse);
in.close();
}
} public class Main {
public static void main (String [] args) {
Scanner sc = new Scanner (System.in);
// 1. 读取四位整数(直接转字符串更方便处理反转和零)
String numStr = sc.next ();
// 2. 用 StringBuilder 的 reverse () 方法反转字符串
String reversedStr = new StringBuilder (numStr)
.reverse ()
.toString ();
// 3. 直接输出反转后的字符串(天然保留前导零)
System.out.println (reversedStr);
sc.close();} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
reserve_print(n);
}
//递归
public static int reserve_print(int n){
if (n > 0){
System.out.print(n%10);
return reserve_print(n/10);
} else {
return n;
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String[] num = in.next().split("");
ArrayList<String> numList = new ArrayList<>(Arrays.asList(num));
Collections.reverse(numList);
numList.forEach(System.out::print);
}
}
} import java.util.Arrays;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder str = new StringBuilder(sc.nextLine());
System.out.println(str.reverse());
}
} import java.util.Scanner;
import java.util.ArrayList;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String s = in.nextLine();
String[] sList=s.split("");
ArrayList<Integer> array=new ArrayList<Integer>();
for(int i=s.length()-1;i>=0;i--){
array.add(Integer.valueOf(sList[i]));
}
for(int i=0;i<array.size();i++){
System.out.print(array.get(i));
}
}
}
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
int num = scanner.nextInt();
//个位
int onesPlace = num % 10;
//十位
int tensPlace = num / 10 % 10;
//百位
int thousandsPlace = num / 100 % 10;
//千位
int tenThousandsPlace = num / 1000 % 10;
System.out.println(onesPlace + "" + tensPlace + "" + thousandsPlace + "" + tenThousandsPlace);
}
}
}
import java.util.Scanner;
/**
*
* @Title 反向输出一个四位数
* @Description 将一个四位数,反向输出。
* 输入描述:
* 一行,输入一个整数n(1000 <= n <= 9999)。
* 输出描述:
* 针对每组输入,反向输出对应四位数。
* @author weijunfu<ijunfu @ qq.com>
* @date 2022/03/18 00:19
* @version 1.0.0
*
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
StringBuilder sb = new StringBuilder(line);
System.out.println(sb.reverse().toString());
in.close();
}
}
import java.util.Scanner;
import static java.lang.Math.pow;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String newnum = "";
while (n>0){
int wei = n % 10;
// System.out.println(wei);
n = n / 10;
// System.out.println(n);
newnum = newnum+wei;
}
System.out.println(newnum);
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int num=input.nextInt();
while(num!=0){
int temp=num%10;
num/=10;
System.out.print(temp);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int temp = num;
int c= 0;
int cnt = 0;
while (temp != 0)
{
c = c *10 + temp % 10;
if(c == 0)
{
cnt++;
}
temp/=10;
}
if (cnt !=0)
{
for (int i=0; i<cnt; i++)
{
System.out.print("0");
}
System.out.print(c);
}
else
{
System.out.println(c);
}
}
} import java.util.Scanner;
public class Main{
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
String str= sc.next();
Integer integer = Integer.parseInt(str);
System.out.println(integer%10+""+integer%100/10+integer%1000/100+integer/1000);
}
}