华为笔试题—汽水瓶

华为笔试题

  • 汽水瓶
    题目要求

package 华为笔试题;

import java.util.Scanner;

/**
 * @Author: Lance
 * @Date: 2018/8/7 15:42
 */
public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int flag = scanner.nextInt();
            if (flag == 0) {
                break;
            } else {
                System.out.println(coutBottle(flag));
            }

        }
    }

    public static int coutBottle(int i) {

        if (i == 1) {
            return 1;
        }
        if (i % 2 != 0) {
            return (i - 1) / 2;
        } else {
            return i / 2;
        }


    }
}


posted @ 2018-08-07 15:57  阳虎为患  阅读(435)  评论(0编辑  收藏  举报