import java.util.Scanner; //輸入一串數字逐個+5後取餘數10,首位數顛倒 class j{ public static void main(String [] args){ //鍵盤輸入 Scanner sc = new Scanner(System.in); int number=sc.nextInt(); int[] a= new int[6];//最多6位數字未檢測超過6位會如何 int index=0; int temp; while(number > 0){ //輸入的數字取餘數10 //如123456取餘數10後得到的是6 a[index] = ((number%10)+5)%10; index++; number/=10;//結尾處除以10後就少一位,如123456除以10得12345 } temp=a[0]; a[0]=a[a.length-1]; a[a.length-1]=temp; for(int i=0;i<index;i++){ System.out.print(a[i]+" ,"); } //j(x); } public static void j(int[] x){ int tempnumber=0; for(int i=0;i<(x.length/2);i++){ tempnumber=x[i]; x[i]=(x[x.length-i-1]+5)%10; x[x.length-i-1]=(tempnumber+5)%10; } tempnumber=x[0]; x[0]=x[x.length-1]; x[x.length-1]=tempnumber; for(int i=0;i<x.length;i++){ System.out.print(x[i]+" ,"); } } }
逐個取出數字
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.