題目:
Given a number n, you are required to output its reverse counterpart. that is, the most significant digit become the list significant digit and so on. There are several test cases for each test group.
Input: Test case count T following by each test case. Example:
5
12000
11111
012
5
-23
Output:
21
11111
21
5
-32
代碼:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
for(int i=0;i<n;i++)
{
String a=s.next();
char[] arr = a.toCharArray();
char t;
char[] b=new char[30];
char[] d=new char[30];
int j=0;
int e=Integer.parseInt(a);
if(e==0)
b[0]='0';
else
{ for(;j<arr.length;j++)
{
if(arr[j]!='0'&&arr[j]!='-')
{
b[j]=arr[j];
}
}
}
if(e<0)
{ System.out.print("-");
for (int c = b.length-1; c>0; c--)
System.out.print(b[c]); }
else
{for (int c = b.length - 1; c>=0; c--)
System.out.print(b[c]);}
System.out.println();
}
}
}
注:輸出和平臺要求的形式一樣,但還是錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/169826.html
標籤:Java相關
