对一个随机数做运算并顺序输出结果

package com.fqs.demo;

import java.util.Random;

public class JiaMi {
    public static void main(String[] args) {
        //比如系统的数字密码是19
        //第一位 1+5=6 6%10=0 求余 公式 (array[index]+5)%10
        //第二位 9+5=14 14%10=4 求余4
        //反转 40
        //4+5=9 9%10 余数9
        //1+5=6 6%10 余数6
        Random sj=new Random();
        int mima=sj.nextInt(100)+1;
        System.out.println("mima:"+mima);
        int []array=new int[100];
        //求位数
        int wei=0;
        for(int temp=mima;mima!=0;mima/=10) {
            array[wei]=mima%10;//个位
wei
++; } System.out.println("wei:"+wei); //每位数+5;对10求余数 循环位数次 //倒叙输出整个数组 for(int i=wei-1;i>=0;i--) { int he=array[i]+5; array[i]=he%10; System.out.println("第"+i+"位:"+array[i]); } } }

 

posted @ 2023-02-01 22:27  胖豆芽  阅读(19)  评论(0编辑  收藏  举报