逐个取出数字

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]+" ,");
		}
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章