逆序輸出整數
阿新 • • 發佈:2019-02-15
Description
編寫程式將整數逆序輸出。如輸入為9876輸出為6789 Main函式中讀入n個整數,輸出n個整數的逆序數
Input
整數個數n n個整數
Output
n個整數的逆序數
Sample Input
3 1234 2323 1112
Sample Output
4321 3232 2111
submit
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); for (int i = 0; i < num; i++) { int data = scan.nextInt(); String string = String.valueOf(data); String reverse = new StringBuffer(string).reverse().toString(); System.out.println(reverse); } scan.close(); } }