zoukankan      html  css  js  c++  java
  • 好久没用IJ写Java 之 《求输入的一个数中包含奇数、偶数、零的个数》

     1 /**
     2  *Created by xuzili at 22:12 on 2018/4/4
     3  */
     4 // 以上注释使用了IntelliJ Idea的File-Settings-Editor-Live Templates-User(Self)提供的/*a+tab键(自定义功能)
     5 import java.util.*;
     6 public class Main {
     7     public static void main(String[] args) {
     8         Scanner in=new Scanner(System.in);
     9         System.out.println("Input x = ");
    10         int x = in.nextInt(),n=0;
    11         int[]y = new int[30];
    12         for (int i=0;x!=0;i++){
    13             y[n] = x%10;
    14             x = x/10;
    15             System.out.println("x的各位数为"+y[n++]);
    16         }
    17         int zero=0,odd=0,even=0;
    18         for(int i=0;i<n;i++){
    19             if(y[i]==0)
    20                 zero++;
    21             else
    22                 switch(y[i]%2){
    23                     case 0:odd++;break;
    24                     case 1:even++;break;
    25                 }
    26         }
    27         System.out.println("奇数"+even);
    28         System.out.println("偶数"+odd);
    29         System.out.println("零"+zero);
    30     }
    31 }

    Live Templates功能的具体使用请参考 https://blog.csdn.net/mhs624014469/article/details/76285258

  • 相关阅读:
    pytest_04
    pytest_03
    pytest_02
    CF 1416C XOR Trie
    CF 1413D
    ZOJ 3725 概率dp
    ZOJ 3726
    位运算
    CF1439C 线段树
    unordered_set
  • 原文地址:https://www.cnblogs.com/stefango/p/8719410.html
Copyright © 2011-2022 走看看