• 统计输入的正数负数的个数


    public class Cal_count {

     public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      int a = 0;//统计整数的个数
      int b = 0;//统计负数的个数
      for(;;){
       System.out.println("请输入一个整数:");
       int x = scanner.nextInt();
       if(x>0){
        a++;
       }else if(x<0){
        b++;
       }else{
        break;
       }
       System.out.println("整数的个数为:"+a);
       System.out.println("负数的个数为:"+b);
      }
     }
    }

  • 相关阅读:
    Bessie Goes Moo
    小P的强力值
    Max Flow
    约瑟夫
    Moocryption
    杂务
    排行榜
    银行贷款
    轰炸
    Contaminated Milk
  • 原文地址:https://www.cnblogs.com/liangxiaoyu/p/4819352.html
Copyright © 2020-2023  润新知