• Java实现 蓝桥杯VIP 算法训练 数位分离


    ** 算法训练 数位分离**
    问题描述
      编写一个程序,输入一个1000 以内的正整数,然后把这个整数的每一位数字都分离出来,并逐一地显示。
      输入格式:输入只有一行,即一个1000以内的正整数。
      输出格式:输出只有一行,即该整数的每一位数字,之间用空格隔开。
      输入输出样例
    样例输入
    769
    样例输出
    7 6 9

    import java.util.Scanner;
    
    
    public class 数位分离 {
    	public static void fun(int n)
    	{
    		if(n>0&&n<=9)
    		{
    			System.out.print(n+" ");
    		}
    		else if(n>10&&n<=99)
    		{
    			int a=n%10;    
    			int b=n/10%10;   
    			System.out.print(b+" "+a+" ");
    		}
    		else if(n>99&&n<=999)
    		{
    			int a=n%10;   
    			int b=n/10%10;   
    			int c=n/100%10;   
    			System.out.print(c+" "+b+" "+a+" ");
    		}
    		 
    		 
    	}
    	public static void main(String[] args)
    	{
    		Scanner in=new Scanner(System.in);
    		int n=in.nextInt();
    		fun(n);
    		 
    	}
    
    
    }
    
    
  • 相关阅读:
    重载运算符 && 构造函数 的写法
    2019 ICPC Asia Xuzhou Regional
    中国剩余定理
    求逆元
    Exgcd
    Leading Robots
    大家好
    AtCoder Grand Contest 047 部分题解
    CodeForces 1389E Calendar Ambiguity 题解
    CodeForces 1380F Strange Addition 题解
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13079218.html
Copyright © 2020-2023  润新知