首页 > 其他分享 >对一个随机数做运算并顺序输出结果

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

时间:2023-02-01 22:46:02浏览次数:40  
标签:10 顺序 运算 int wei mima 随机数 array out

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

 

标签:10,顺序,运算,int,wei,mima,随机数,array,out
From: https://www.cnblogs.com/haha1988/p/17084344.html

相关文章