2015年第六届蓝桥杯省赛 Java A 组真题
第一题

public class Q1 {
public static void main(String[] args) {
int n = 1543, ans = 0;
while (n > 0) {
if (n % 2 != 0) {
n--;
ans++;
}
n /= 2;
}
System.out.println(ans);
}
}
答案:5
第二题

import java.util.Calendar;
public class Q2 {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2014);
// 月份从 0 开始
cal.set(Calendar.MONTH, 10);
cal.set(Calendar.DAY_OF_MONTH, 9);
cal.add(Calendar.DAY_OF_MONTH, 1000);
System.out.println(cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH));
}
}
答案:2017-08-05
第三题

public class